diff --git a/package.json b/package.json index 491d4b6..5d842a6 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "1.0.0", "description": "", "scripts": { - "start": "node server.js", + "dev": "node serverdev.js", + "build": "webpack --config ./webpack.production.config.js --progress --profile --colors", + "start": "npm run build && node server.js", "lint": "eslint src" }, "author": "Tanner Collin (http://github.com/tannercollin)", @@ -18,6 +20,7 @@ "webpack-dev-server": "^1.8.2" }, "dependencies": { + "body-parser": "^1.15.2", "freezer-js": "^0.6.0", "react": "^0.13.0", "react-router": "^0.13.3" diff --git a/server.js b/server.js index 5ac2b33..1351079 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,30 @@ -var webpack = require('webpack'); -var WebpackDevServer = require('webpack-dev-server'); -var config = require('./webpack.config'); +const path = require('path'); +const express = require('express'); +const bodyParser = require('body-parser'); -new WebpackDevServer(webpack(config), { - publicPath: config.output.publicPath, - hot: true, - historyApiFallback: true -}).listen(3000, 'localhost', function (err, result) { +const app = express(); + +const host = 'http://localhost'; +const port = 3000; + +app.use(bodyParser.urlencoded({ extended: false })); + +app.use('/static', express.static(path.join(__dirname, 'dist'))); +app.use('/assets', express.static(path.join(__dirname, 'assets'))); +app.get('/', (req, res) => { + res.sendFile(path.join(__dirname, 'index.html')); +}); + +app.post('*', (req, res) => { + console.log("to: " + req.path); + console.log(Object.keys(req.body)[0]); + res.end(); +}); + +app.listen(port, 'localhost', (err) => { if (err) { console.log(err); + return; } - - console.log('Listening at localhost:3000'); + console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port); }); diff --git a/serverdev.js b/serverdev.js new file mode 100644 index 0000000..28220e1 --- /dev/null +++ b/serverdev.js @@ -0,0 +1,16 @@ +var webpack = require('webpack'); +var WebpackDevServer = require('webpack-dev-server'); +var config = require('./webpack.config'); + +new WebpackDevServer(webpack(config), { + publicPath: config.output.publicPath, + hot: true, + historyApiFallback: true, + noInfo: true +}).listen(3000, 'localhost', function (err, result) { + if (err) { + console.log(err); + } + + console.log('Listening at localhost:3000'); +}); diff --git a/webpack.production.config.js b/webpack.production.config.js new file mode 100644 index 0000000..f7f92fe --- /dev/null +++ b/webpack.production.config.js @@ -0,0 +1,30 @@ +var path = require('path'); +var webpack = require('webpack'); + +module.exports = { + devtool: 'source-map', + entry: [ + './src/index' + ], + output: { + path: path.join(__dirname, 'dist'), + filename: 'bundle.js', + publicPath: '/static/' + }, + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new webpack.optimize.UglifyJsPlugin({ + compressor: { + warnings: false + } + }), + new webpack.NoErrorsPlugin() + ], + module: { + loaders: [{ + test: /\.js$/, + loaders: ['babel'], + include: path.join(__dirname, 'src') + }] + } +};