-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (44 loc) · 1.78 KB
/
index.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
53
54
55
56
57
58
"use strict";
const express = require('express');
const app = express();
const path = require('path');
const compression = require('compression');
// Production middlewares
const publicPath = '/';
const outputPath = path.resolve(process.cwd(), 'build');
// compression middleware compresses your server responses which makes them
// smaller (applies also to assets). You can read more about that technique
// and other good practices on official Express.js docs http://mxs.is/googmy
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(compression());
app.use(publicPath, express.static(outputPath));
app.get('/', (req, res) => res.sendFile(path.resolve(outputPath, 'index.html')));
app.get('/appcache/manifest.html', (req, res) => {res.sendFile(path.resolve(outputPath, 'appcache/manifest.html'))});
app.get('/appcache/manifest.appcache', (req, res) => {res.sendFile(path.resolve(outputPath, 'appcache/manifest.appcache/'))});
app.get('/build/:file', (req, res, next) => {
let file = req.params.file;
let filePath = path.resolve(outputPath, file);
res.sendFile(path.resolve(outputPath, filePath));
});
app.get('/:file', (req, res, next) => {
console.log(file);
let file = req.params.file;
let filePath = path.resolve(outputPath, file);
if (file === '/login') {
res.sendFile(path.resolve(outputPath, 'index.html'));
}
res.sendFile(path.resolve(outputPath, 'index.html'));
return;
});
const port = process.env.PORT || 3000;;
app.listen(port, (err) => {
if (err) {
console.log(err);
}
console.log(`listening on port ${port}`);
console.log(outputPath);
});