-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (30 loc) · 1.07 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
var express = require('express');
var http = require('http');
var https = require('https');
var fs = require('fs');
var favicon = require('serve-favicon');
var compression = require('compression');
var jsonServer = require('json-server');
var lessMiddleware = require('less-middleware');
var app = express();
var server = http.Server(app);
// port for http server
app.set('port', 7575);
app.use(favicon(__dirname + '/src/favicon.ico'));
// Enable compression of responses
app.use(compression());
// Compile .less files to .css
app.use(lessMiddleware(__dirname + '/src'));
// Serve static files such as HTML, CSS, JavaScript, etc
app.use(express.static(__dirname + '/src'));
// Mock rest API
app.use('/api', jsonServer.router('db.json'));
// Direct all non-static traffic to index.html
// The client-side backbone router handles the loading of content
app.get('*', function (req, res){
res.sendFile(__dirname + '/src/index.html');
});
// Start the web server
server.listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});