-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (41 loc) · 1.64 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
43
44
45
46
47
48
49
50
51
require('app-module-path').addPath(__dirname);
require('marko/express');
require('marko/node-require');
function requireNoOp(module, filename) { /* no-op */ }
require.extensions['.less'] = requireNoOp;
require.extensions['.css'] = requireNoOp;
const express = require('express');
const compression = require('compression'); // Provides gzip compression for the HTTP response
const serveStatic = require('serve-static');
// If the process was started using browser-refresh then enable
// hot reloading for certain types of files to short-circuit
// a full process restart. You *should* use browser-refresh
// in development: https://www.npmjs.com/package/browser-refresh
require('marko/browser-refresh').enable();
const contentType = require('./middlewares/contentType');
const fs = require('fs');
const pages = fs.readdirSync('./src/pages');
const app = express();
const port = process.env.PORT || 8080;
// Enable gzip compression for all HTTP responses
app.use(compression());
// Allow all of the generated files under "static" to be served up by Express
app.use('/static', serveStatic(__dirname + '/static'));
app.use('/', serveStatic(__dirname + '/'));
//set content-type html
app.use(contentType);
// Map the "/" route to the home page
app.get(`/`, require(`src/pages/home`))
//map more routes to the router
pages.map(page => app.get(`/${page}`, require(`src/pages/${page}`)))
app.listen(port, function(err) {
if (err) {
throw err;
}
console.log('Listening on port %d', port);
// The browser-refresh module uses this event to know that the
// process is ready to serve traffic after the restart
if (process.send) {
process.send('online');
}
});