-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (36 loc) · 1.32 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
'use strict';
var express = require('express');
var app = express();
var volleyball = require('volleyball');
var nunjucks = require('nunjucks');
var routes = require('./routes');
var fs = require('fs');
var path = require('path');
var mime = require('mime');
var client = require('./db/index.js');
var bodyParser = require('body-parser');
// templating boilerplate setup
app.engine('html', nunjucks.render); // how to render html templates
app.set('view engine', 'html'); // what file extension do our templates have
nunjucks.configure('views', { noCache: true }); // where to find the views, caching off
// logging middleware
app.use(volleyball);
// body parsing middleware
app.use(bodyParser.urlencoded({ extended: true })); // for HTML form submits
app.use(bodyParser.json()); // would be for AJAX requests
// start the server
app.listen(1337, function(){
console.log('listening on port 1337');
});
app.use(express.static(path.join(__dirname, '/public')));
// modular routing that uses io inside it
app.use('/', routes);
// // manually-written static file middleware
// app.use(function(req, res, next){
// var mimeType = mime.lookup(req.path);
// fs.readFile('./public' + req.path, function(err, fileBuffer){
// if (err) return next();
// res.header('Content-Type', mimeType);
// res.send(fileBuffer);
// });
// });