-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
99 lines (82 loc) · 2.35 KB
/
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const port = process.env.PORT || 8888;
const express = require('express');
const compression = require('compression');
const minify = require('express-minify');
var app = express();
const db = require('./utils/database');
const {resizingMiddleware} = require('./utils/resizeMiddleware');
const {setCache} = require('./utils/cache');
app.enable('trust proxy');
const shouldCompress = (req, res) => {
if (req.headers['x-no-compression']) {
// Will not compress responses, if this header is present
return false;
}
// Resort to standard compression
return compression.filter(req, res);
};
// Compress all HTTP responses
app.use(compression({
filter: shouldCompress,
}));
app.use(setCache);
/*app.use(minify({
cache: "cache/",
uglifyJsModule: null,
errorHandler: null,
jsMatch: /.*\.js/,
cssMatch: /.*\.css/,
jsonMatch: /.*\.json/,
sassMatch: /.*\.scss/,
lessMatch: /.*\.less/,
stylusMatch: /.*\.stylus/,
coffeeScriptMatch: /.*\.coffeescript/,
}));
*/
app.use(minify({
cache: false,
uglifyJsModule: require('uglify-js'),
jsMatch: /javascript/,
cssMatch: /css/,
jsonMatch: /json/,
sassMatch: /scss/,
lessMatch: /less/,
stylusMatch: /stylus/,
coffeeScriptMatch: /coffeescript/,
}));
app.use(function(request, response, next) {
if (process.env.NODE_ENV != 'development' && !request.secure) {
return response.redirect("https://" + request.headers.host + request.url);
}
next();
});
// set the view engine to ejs
app.set('view engine', 'ejs');
app.use(/.*\.(jpe?g|png)/, resizingMiddleware); // If resizing is needed
app.use('/bootstrap', express.static('node_modules/bootstrap/dist'));
app.use('/bootstrap-icons', express.static('node_modules/bootstrap-icons'));
app.use('/theme', express.static('eduport.webestica.com/assets'));
app.use('/static', express.static('public'));
// index page
app.get('/', async function(req, res) {
res.render('pages/index', {
page_title: "Homepage / Headstarter",
jobs: await db.jobs.find().map((job) => {
return {
'_id': job._id,
'name': job.name,
'category': 'Category',
'level': 'Level required'
};
}).toArray()
});
});
// about page
app.get('/about', function(req, res) {
res.render('pages/about', {
page_title: "About us / Headstarter"
});
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});