-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (41 loc) · 1.3 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
// node modules
var express = require('express'),
bodyParser = require('body-parser'),
logger = require('morgan')('dev'),
nodeSass = require('node-sass-middleware');
// app instantiation
var app = express();
// req-res logging
app.use(logger);
// sass middleware
var sassMiddleware = nodeSass({
src: __dirname + '/assets',
dest: __dirname + '/public',
debug: true
});
app.use(sassMiddleware);
// static middleware (if we have a matching file, just send it back)
app.use(express.static(__dirname + '/public'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
// body parsing (if the http request has a body, make it a req.body object)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// root route
app.use('/', require('./routes/index'));
// catch 404 (i.e., no routes were hit) and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// handle all errors (anything passed into next())
app.use(function(err, req, res, next) {
res.status(err.status || 500);
console.error(err);
res.send({error: err});
});
// server initialization
var port = 1337;
app.listen(port, function () {
console.log('The server is ALIVE! And listening to port', port);
});