-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·95 lines (80 loc) · 2.76 KB
/
server.js
File metadata and controls
executable file
·95 lines (80 loc) · 2.76 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
server.js
Author: Niraj Menon
First creation date: 7/20/19
Description:
Entry point for simulator application.
Sets up and configures the Express app which will handle the regular
HTTP routes, including features for login, signup, password reset,
session handling, landing pages, static content, etc.
*/
const fs = require('fs-extra'),
path = require('path'),
process = require('process'),
express = require ('express'),
app = express(),
cors = require ('cors'),
expressSanitizer = require('express-sanitizer'),
favicon = require('serve-favicon');
app.use (expressSanitizer());
app.use (express.json());
// eslint-disable-next-line no-undef
app.use (favicon(path.join(__dirname, 'favicon.ico')));
app.use (cors(['https://verilog.ecn.purdue.edu', 'https://engineering.purdue.edu']));
app.use ('/assets', express.static(path.join(__dirname, '/assets')));
app.use ('/md', express.static(path.join(__dirname, '/md')));
app.get ('/', async function (req, res) {
res.sendFile (__dirname + '/index.html');
});
app.get ('/help', function (req, res) {
res.send (fs.readFileSync (__dirname + '/manual.html').toString())
});
app.get ('/help/*', function (req, res) {
res.sendFile (__dirname + '/md/' + req.url.replace ('/help/', ''))
});
app.get ('/support', function (req, res) {
try {
var files = fs.readdirSync (`${__dirname}/support`);
files = files.filter (f => f.endsWith('.v') || f.endsWith('.sv'));
res.send (files);
}
catch (err) {
res.send ([]);
}
});
function debugLog (message) {
try {
console.log (getTime() + ": " + message)
}
catch(err) {
console.log (getTime())
console.log (message)
}
}
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
function exitHandler (options) {
if (options.cleanup) debugLog ("Fatal SIGINT occurred")
if (options.exit) process.exit()
}
process.on ('SIGTERM', function () {
debugLog ("Simulator main process was SIGTERM'ed! Exiting!")
process.exit()
})
process.on ('SIGINT', exitHandler.bind (null, {exit: true}))
process.on ('uncaughtException', function (err) {
debugLog ('uncaughtException in code! Details: \n')
console.error (err)
})
function getTime()
{
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
var min = (today.getMinutes() < 10 ? '0' + today.getMinutes() : today.getMinutes())
var sec = (today.getSeconds() < 10 ? '0' + today.getSeconds() : today.getSeconds())
var time = today.getHours() + ":" + min + ":" + sec;
return (date + ' ' + time);
}
module.exports = app