-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
52 lines (41 loc) · 1.56 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
52
require('marko/express')
require('marko/node-require')
let path = require('path')
let express = require('express')
let compression = require('compression') // Provides gzip compression for the HTTP response
let isProduction = process.env.NODE_ENV === 'production'
if (!isProduction) { require('marko/browser-refresh').enable() }
// Configure lasso to control how JS/CSS/etc. is delivered to the browser
require('lasso').configure({
plugins: [
'lasso-marko', // Allow Marko templates to be compiled and transported to the browser
],
outputDir: path.join(__dirname, '/static'), // Place all generated JS/CSS/etc. files into the "static" dir
bundlingEnabled: isProduction, // Only enable bundling in production
minify: isProduction, // Only minify JS and CSS code in production
fingerprintsEnabled: isProduction // Only add fingerprints to URLs in production
})
let app = express()
let 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(require('lasso/middleware').serveStatic())
app.get('/*', function(req, res){
console.log("path", req.path);
res.marko(
require('./src/components/template.marko'),
{ initialRoute: req.path }
);
})
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')
}
})