-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevServer.js
More file actions
77 lines (63 loc) · 1.96 KB
/
devServer.js
File metadata and controls
77 lines (63 loc) · 1.96 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
74
75
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var app = express();
var compiler = webpack(config);
var webpackHotMiddleware = require("webpack-hot-middleware");
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/key.pem', 'utf8');
var certificate = fs.readFileSync('sslcert/cert.pem', 'utf8');
var credentials = {key: privateKey, cert: certificate};
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
hot: true,
historyApiFallback: true,
filename: 'bundle.js',
stats: {
colors: true,
},
publicPath: config.output.publicPath
}));
app.use(webpackHotMiddleware(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('/', function(req, res) {
console.log("2");
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/offline.min.js', function(req, res) {
console.log("cek");
res.sendFile(path.join(__dirname, 'offline.min.js'));
});
app.get('/manifest.json', function(req, res) {
console.log("3");
res.sendFile(path.join(__dirname, 'manifest.json'));
});
app.get('/service-worker.js', function(req, res) {
console.log("5");
if(path.extname('service-worker.js') == '.js'){
res.setHeader('content-type', 'application/javascript');
}
res.sendFile(path.join(__dirname, 'service-worker.js'));
});
app.get('/node_modules/axios/dist/axios.js', function(req, res) {
console.log("4");
res.sendFile(path.join(__dirname, 'node_modules/axios/dist/axios.js'));
});
/*app.listen(7770, 'localhost', function(err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:7770');
});*/
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(7770);
httpsServer.listen(8443);