-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (48 loc) · 1.55 KB
/
index.js
File metadata and controls
55 lines (48 loc) · 1.55 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
const initCACCL = require('caccl/script');
const express = require('express');
// Import helpers
const doLaunches = require('./helpers/doLaunches');
// Import constants
const PORT = require('./constants/PORT');
const main = async () => {
// Create a server
const app = express();
// Set up ejs
app.set('view engine', 'ejs');
// Allow connections from localhost
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'localhost');
res.setHeader('Access-Control-Allow-Credentials', true);
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
next();
});
// Start the server
app
.listen(PORT, async () => {
// Start launches!
try {
await doLaunches(app);
} catch (err) {
// eslint-disable-next-line no-console
console.log('\nOops! An issue has occurred:');
// eslint-disable-next-line no-console
console.log(err);
process.exit(1);
}
})
.on('error', (err) => {
if (err.message.includes('EADDRINUSE')) {
// Another version of the server is running!
// eslint-disable-next-line no-console
console.log('Oops! Another test script is still running.\n\nSolution:\nIn a terminal window, type "sudo lsof -ti tcp:8098 | xargs kill" and press enter\n');
process.exit(0);
}
// eslint-disable-next-line no-console
console.log(`Could not start launches because an error occurred: ${err.message}`);
});
};
// Start main
main().catch(console.log);