Skip to content

Commit

Permalink
feat(node): create production server
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Apr 4, 2016
1 parent 7a53dcd commit abed438
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"start": "npm run server",
"server": "npm run server:dev",
"server:dev": "webpack-dev-server --inline --progress --profile --colors --watch --display-error-details --display-cached --content-base src/",
"server:prod": "node src/server/httpServer.js",
"webdriver:update": "webdriver-manager update",
"webdriver:start": "webdriver-manager start",
"static-server": "node src/server/staticServer.js",
Expand Down
19 changes: 19 additions & 0 deletions src/server/httpServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var fs = require('fs');
var http = require('http');
var serveStatic = require('serve-static');
var finalhandler = require('finalhandler');

var settings = require('./settings').settings;
var host = settings.httpServer.host || 'localhost';
var port = settings.httpServer.port || 8080;

var serve = serveStatic('/dist', { 'index': ['index.html'] });

var server = http.createServer(function(req, res) {
var done = finalhandler(req, res);
serve(req, res, done);
})

server.listen(port, host);

console.log(host + ':' + port);
5 changes: 1 addition & 4 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
var helpers = require('./helpers');
var settings = require('./src/server/settings').settings;

var fs = require('fs');
var version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;

var webpack = require('webpack');
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
var DefinePlugin = require('webpack/lib/DefinePlugin');
Expand Down Expand Up @@ -39,7 +36,7 @@ module.exports = {
},

output: {
path: helpers.root('dist/' + version),
path: helpers.root('dist'),
filename: '[name].[chunkhash].bundle.js',
sourceMapFilename: '[name].[chunkhash].bundle.map',
chunkFilename: '[id].[chunkhash].chunk.js'
Expand Down

0 comments on commit abed438

Please sign in to comment.