-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
36 lines (29 loc) · 1020 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
34
35
36
#!/usr/bin/env node
"use strict";
let fs = require('fs');
let path = require('path');
let express = require('express');
let app = express();
app.listen(4000, () => {
console.log('Listening on port 4000');
});
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://' + __dirname + '/example-project/')
.replace('#htmlPath#', 'file://' + __dirname + '/example-project/project.html')
.replace('#cssPath#', 'file://' + __dirname + '/example-project/style.css')
.replace('#jsPath#', 'file://' + __dirname + '/example-project/source.js');
return callback(null, rendered)
});
});
app.set('views', '');
app.set('view engine', 'html');
app.get('/', (req, res) => {
res.render('index.html');
});