mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
b4d3eab02c
Add foreman configuration for Heroku: - To test production configuration execute NODE_ENV=production foreman start - Database connection configuration now handles "use_env_variable" which should be defined as a environment variable such as "DATABASE_URL" with a proper database URI connection string, ie: postgres://user:password@db.example.com:5432/database - Added package.json configuration to run migrations and db seed after `npm install` Update frontend models to match sequelize definition. Update views to work according to the changes above. Handling isCompleted and parentId apropiately for PostgreSQL databases
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
var application_root = __dirname,
|
|
express = require('express'),
|
|
app = express(),
|
|
path = require('path'),
|
|
config = require('config'),
|
|
orm = require('./orm').configure(config.get('database')),
|
|
Tasks = require('./db/models/task').instance(orm),
|
|
server = require('http').createServer(app),
|
|
io = require('socket.io').listen(server);
|
|
|
|
app.configure(function() {
|
|
app.use(express.bodyParser());
|
|
app.use(express.methodOverride());
|
|
app.use(app.router);
|
|
app.use(express.static( path.join( application_root, 'public')));
|
|
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
|
|
});
|
|
|
|
server.listen(config.get('port'), function() {
|
|
console.log( 'Express server listening on port %d in %s mode', config.get('port'), app.settings.env );
|
|
});
|
|
|
|
app.get('/tasks', function(req,res){
|
|
Tasks.all().success(function(tasks){
|
|
res.send(tasks);
|
|
});
|
|
});
|
|
|
|
app.post('/tasks', function(req,res){
|
|
Tasks.create({
|
|
content: req.body.content,
|
|
parent: parseInt(req.body.parent_id) || 0,
|
|
isCompleted: false
|
|
}).success(function(task){
|
|
res.send(task);
|
|
});
|
|
});
|
|
|
|
app.put('/tasks/:id', function(req,res){
|
|
console.log(req.body.isCompleted);
|
|
Tasks.find(req.params.id).success(function(task){
|
|
task.content = req.body.content;
|
|
task.isCompleted = req.body.isCompleted == 1;
|
|
task.save().success(function(task){
|
|
res.send(task);
|
|
})
|
|
});
|
|
});
|
|
|
|
app.delete('/tasks/:id', function(req,res){
|
|
Tasks.find(req.params.id).success(function(task){
|
|
task.destroy().success(function(){
|
|
res.send('');
|
|
});
|
|
})
|
|
});
|
|
|
|
io.sockets.on('connection', function (socket) {
|
|
socket.on('task', function (data) {
|
|
socket.broadcast.emit('task', data);
|
|
});
|
|
});
|