-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (44 loc) · 1.38 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var express = require('express'),
sprite = require('node-sprite'),
stylus = require('stylus'),
graph = require('./private/graph');
var app = express(), compileStylus;
// boot up
configureSprites(function (err, compileStylus) {
if (err)
console.log(err);
configureApp(compileStylus);
});
function configureApp(compileStylus) {
app.configure(function () {
//app.set('view engine', 'jade');
//app.set('views', __dirname + '/views');
app.use(stylus.middleware({ src: __dirname + '/public', compile: compileStylus }));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: process.env.NEO4J_URL || 'secret' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
// todo: move this to a separate module
app.post('/sentences', function (req, res) {
graph.insertSentences(req.body.sentences, function (err, result) {
if (err)
console.log(err);
res.writeHead(200, { "Content-Type": "text/json" });
res.end(JSON.stringify(err ? { error: err } : result));
})
});
app.listen(process.env.PORT || 8081);
}
function configureSprites(callback) {
sprite.stylus({ path: './public/img', httpPath: '/img' }, function (err, helper) {
if (err)
console.log(err);
callback(null, function (str, path) {
return stylus(str)
.set('filename', path)
.define('sprite', helper.fn);
});
});
}