-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
53 lines (46 loc) · 1.23 KB
/
server.ts
File metadata and controls
53 lines (46 loc) · 1.23 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
/*
* Firestarter.io
*
* Copyright (C) 2022 Blue Ohana, Inc.
* All rights reserved.
* The information in this software is subject to change without notice and
* should not be construed as a commitment by Blue Ohana, Inc.
*
*/
/**
* Express server that serves the application
*/
import * as fs from 'fs';
import * as express from 'express';
import * as dotenv from 'dotenv';
import * as bp from 'body-parser';
import * as cors from 'cors';
import { PORT, PURGE_TILES, TILE_DIR } from '~config';
import logger from '~core/utils/Logger';
import router from './router';
dotenv.config();
// Set up app
const app = express();
const port: string = process.env.PORT ?? PORT;
// Set up middlewares
app.use(bp.json());
app.use(bp.urlencoded({ extended: true }));
app.use(cors());
// Set up routes
app.use('/', router);
// Start server
const server = app.listen(port, () => {
logger.server(`Firestarter is listening on port ${port} 🎧\n`);
});
// Perform cleanup
process.on('SIGINT', function () {
server.close(() => {
logger.server('Shutting down Firestarter');
if (PURGE_TILES) {
fs.rmdirSync(TILE_DIR, { recursive: true });
logger.server('🧹 Removing all tile images...');
}
logger.server('Goodbye!\n\n');
process.exit();
});
});