-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (32 loc) · 1.03 KB
/
server.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
var express = require('express');
var mongojs = require('mongojs');
var bodyParser = require('body-parser');
var apiRoutes = require('./routes/apiRoutes');
var app = express();
app.set('view engine', 'html');
app.use(function (req, res, next) {
if (req.url.match(/^\/(scripts|css|js|img|fonts|views)\/.+/)) {
res.setHeader('Cache-Control', 'public, max-age=86400');
}
next();
});
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use('/scripts', express.static(__dirname + '/node_modules/'));
app.use('/api/', apiRoutes);
app.use('/category/*', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.use('/404', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.use('/*', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.use(function(req, res) { //put this at end
console.log('404 page');
res.status(404);
res.redirect('/404');
});
app.listen(80);
console.log('Up: http://localhost:80');