-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
78 lines (68 loc) · 2.35 KB
/
server.js
File metadata and controls
78 lines (68 loc) · 2.35 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
76
77
78
const path = require('path');
const express = require('express');
const _config = require('./config');
module.exports = {
app: function () {
const app = express();
const indexPath = _config.paths.index_path;
const swPath = _config.paths.sw_path;
const publicPath = express.static(_config.paths.public_path);
app.get('/public/bundle.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
// loader
app.get('/public/css/loader.css', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Type', 'text/css');
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
// jquery
app.get('/public/vendor/jquery/jquery.min.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
// font-awesome
app.get('/public/vendor/font-awesome/css/font-awesome.min.css', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Type', 'text/css');
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
// materialize
app.get('/public/vendor/materialize/css/materialize.min.css', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Type', 'text/css');
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
app.get('/public/vendor/materialize/js/materialize.min.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Cache-Control', 'public, max-age=86400000');
res.set('Content-Encoding', 'gzip');
next();
});
app.get('/public/images/*', function (req, res, next) {
res.set('Cache-Control', 'public, max-age=86400000');
next();
});
app.use('/public', publicPath);
app.get('*', function (req, res) {
if (req.url.indexOf('service-worker') !== -1){
res.set('Content-Type', 'text/javascript');
res.sendFile(swPath);
} else {
res.sendFile(indexPath);
}
});
return app;
}
}