mirror of
https://github.com/koodiklinikka/koodiklinikka.fi.git
synced 2026-02-23 05:55:48 +00:00
add development proxy for API
This commit is contained in:
16
README.md
16
README.md
@@ -1,4 +1,4 @@
|
||||
# KOODIKLINIKKA
|
||||
# Koodiklinikka
|
||||
|
||||
## Getting things up and running
|
||||
- Install [Node.js](http://nodejs.org)
|
||||
@@ -9,7 +9,8 @@
|
||||
npm install
|
||||
npm start
|
||||
open http://localhost:9001 in your browser
|
||||
````
|
||||
```
|
||||
|
||||
### Enable LiveReload
|
||||
Install [LiveReload for Chrome](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en)
|
||||
|
||||
@@ -22,9 +23,14 @@ Install [LiveReload for Chrome](https://chrome.google.com/webstore/detail/livere
|
||||
* Builds everything
|
||||
|
||||
Minification, uglification and other tasks you're expected to run before deploying your product can be made by running the build command with env variable NODE_ENV set to "production"
|
||||
|
||||
NODE_ENV=production npm run build
|
||||
|
||||
```
|
||||
NODE_ENV=production npm run build
|
||||
```
|
||||
## API server
|
||||
API proxy can be defined with **SERVER** environment variable.
|
||||
```
|
||||
SERVER=http://localhost:9000 npm start
|
||||
```
|
||||
## Development guidelines
|
||||
* **public** - directory should be dedicated only to compiled/copied files from **src** - directory.
|
||||
It should be possible to delete directory completely and after **npm start** or **npm run build** everything should be as they were before the deletion.
|
||||
|
||||
23
gulpfile.js
23
gulpfile.js
@@ -18,6 +18,7 @@ var browserify = require('browserify'),
|
||||
streamify = require('gulp-streamify'),
|
||||
stylus = require('gulp-stylus'),
|
||||
uglify = require('gulp-uglify'),
|
||||
httpProxy = require('http-proxy'),
|
||||
watchify = require('watchify');
|
||||
|
||||
var production = process.env.NODE_ENV === 'production';
|
||||
@@ -105,9 +106,25 @@ gulp.task('assets', function() {
|
||||
});
|
||||
|
||||
gulp.task('server', function() {
|
||||
return require('http').createServer(ecstatic({
|
||||
root: path.join(__dirname, 'public')
|
||||
})).listen(9001);
|
||||
var staticHandler = ecstatic({root: path.join(__dirname, 'public')});
|
||||
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
changeOrigin: true,
|
||||
target: process.env.SERVER || 'http://koodiklinikka.fi/api'
|
||||
});
|
||||
|
||||
proxy.on('error', function(err) {
|
||||
return console.error(err);
|
||||
});
|
||||
|
||||
return require('http').createServer(function(req, res) {
|
||||
if(req.url.indexOf('/api') > -1) {
|
||||
req.url = req.url.replace('/api', '');
|
||||
proxy.web(req, res);
|
||||
return;
|
||||
}
|
||||
staticHandler.apply(this, arguments);
|
||||
}).listen(9001);
|
||||
});
|
||||
|
||||
gulp.task('watch', function() {
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"gulp-stylus": "1.3.3",
|
||||
"gulp-uglify": "~1.0.1",
|
||||
"gulp-util": "~3.0.1",
|
||||
"http-proxy": "^1.8.1",
|
||||
"jsx-transform": "^0.10.1",
|
||||
"karma": "~0.12.21",
|
||||
"karma-chrome-launcher": "~0.1.4",
|
||||
|
||||
Reference in New Issue
Block a user