Created
December 8, 2015 12:21
-
-
Save pekkis/3d843aae2c7a9532923c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save body-parser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var port = 8888; | |
import uuid from 'node-uuid'; | |
import { List } from 'immutable'; | |
var path = require('path'); | |
var url = require('url'); | |
var express = require('express'); | |
var webpack = require('webpack'); | |
var config = require('../webpack.config.dev'); | |
var bodyParser = require('body-parser') | |
var app = express(); | |
var compiler = webpack(config); | |
app.use(require('webpack-dev-middleware')(compiler, { | |
noInfo: true, | |
publicPath: config.output.publicPath | |
})); | |
app.use(bodyParser.json()) | |
let todos = List.of( | |
{ | |
id: uuid.v4(), | |
text: 'Get 100 litres of battery acid', | |
done: true, | |
}, | |
{ | |
id: uuid.v4(), | |
text: 'Get gardening tools', | |
done: true, | |
}, | |
{ | |
id: uuid.v4(), | |
text: 'Carve up the "meat"', | |
done: false, | |
}, | |
{ | |
id: uuid.v4(), | |
text: 'Liquidate the pieces', | |
done: false, | |
}, | |
{ | |
id: uuid.v4(), | |
text: 'Dump the acid in the Danube', | |
done: false, | |
} | |
); | |
app.use(require('webpack-hot-middleware')(compiler)); | |
app.get('/api/todo', function(req, res, next) { | |
setTimeout( | |
function() { | |
res.send(todos.toJS()); | |
}, | |
Math.random() * 3 | |
); | |
}); | |
app.post('/api/todo', function(req, res, next) { | |
todos = List(req.body); | |
res.send(['ok']); | |
}); | |
app.get('*', function(req, res, next) { | |
res.sendFile(path.join(__dirname, '/../web/index.dev.html')); | |
}); | |
app.listen(port, 'localhost', function(err) { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
console.log('Listening at http://localhost:' + port); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment