-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (42 loc) · 1.43 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
var express = require('express'); // For routing
var jade = require('jade'); // For templates
var bodyParser = require('body-parser'); // For getting post params
// Routes
var StaticServe = require('./routes/StaticServe');
var Index = require('./routes/Index');
var AddressTemplate = require('./routes/AddressTemplate');
var UpdateNote = require('./routes/UpdateNote');
var DeleteNote = require('./routes/DeleteNote');
var MakeNote = require('./routes/MakeNote');
// Address of database
var dbURI = "mongodb://localhost:27017/NoteTool"
// Folder where public files are
var publicDir = __dirname + '/public/';
var app = express();
// Set up template engine
app.set('views', publicDir)
.set('view engine', 'jade');
// Set up post parameters
app.use(bodyParser.json())
.use(bodyParser.urlencoded({extended:true}));
// Routes for GET requests
app.get('/:type(css|js)/:name',
StaticServe(publicDir))
.get('/',
Index(dbURI))
.get('/:template(Notes|NewNote|Edit)/:address?',
AddressTemplate(dbURI));
// Routes for POST requests
app.post('/MakeNote',
MakeNote(dbURI))
.post('/UpdateNote/:address',
UpdateNote(dbURI));
// Routes for DELETE requests
app.delete('/Delete/:address',
DeleteNote(dbURI));
// Start server
var server = app.listen(8080, function() {
var host = server.address().address;
var port = server.address().port
console.log("App running at https://%s:%s",host,port);
});