-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (26 loc) · 875 Bytes
/
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
#!/usr/bin/env node
"use strict";
const fs = require('fs');
const express = require('express');
const port = process.env.PORT || 8000;
const app = express();
app.use('/dist', express.static('dist', {
extensions: 'js'
}));
// This serves the current file paths to the app so it can edit the right files
app.engine('html', (filePath, options, callback) => {
fs.readFile(filePath, (err, content) => {
if (err) return callback(err);
let rendered = content.toString()
.replace('#rootPath#', 'file:///usr/src/app/sources/')
.replace('#jsPath#', 'file:///usr/src/app/sources/file.js');
return callback(null, rendered)
});
});
app.set('views', '');
app.set('view engine', 'html');
// Handles HTML5 style requests
app.get('/*', function(req, res) {
res.render('index.html');
});
app.listen(port, () => console.log(`Listening on port ${port}`));