This repository was archived by the owner on Mar 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·73 lines (65 loc) · 1.7 KB
/
server.js
File metadata and controls
executable file
·73 lines (65 loc) · 1.7 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env node
'use strict';
// Make sure that you enable unsecure localhost in chrome!
const https = require('https');
const fs = require('fs');
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
const webpack = require('webpack');
const webpackConfig = require(__dirname + '/webpack.config.js');
const port = 8080;
let isFresh = true;
// Check for a config file and use it
let loaderConfig;
try {
loaderConfig = JSON.parse(fs.readFileSync("./loader.config", "utf8"));
webpackConfig.entry = loaderConfig.entry;
} catch (e) {
/* continue */
}
// setup webpack
if (process.argv[2]) {
webpackConfig.entry = process.argv[2];
}
// Check to see if we can find the entry point
if (!fs.existsSync(webpackConfig.entry)) {
console.error("Could not find entry point. Failed to find:", webpackConfig.entry);
process.exit(1);
}
const compiler = webpack(webpackConfig);
const watching = compiler.watch({}, (err, stats) => {
if (err) {
console.error(err);
} else {
isFresh = true;
}
})
app.get('/', function(req, res) {
fs.readFile('./src/script.js', (err, data) => {
if (err) {
console.log('error: ', err);
} else {
res.end(data);
}
})
// fs.readFile('./dist/script.js', (err, data) => {
// if (err) {
// console.log('error: ', err);
// } else {
// res.end(data);
// }
// })
isFresh = false;
});
app.get('/poll', function(req, res) {
res.send(isFresh);
})
const httpsOptions = {
key: fs.readFileSync(__dirname + '/key.pem'),
cert: fs.readFileSync(__dirname + '/cert.pem')
};
const server = https.createServer(httpsOptions, app).listen(port, () => {
console.log('server running at ' + port)
});