-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
57 lines (50 loc) · 1.58 KB
/
app.ts
File metadata and controls
57 lines (50 loc) · 1.58 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
import {Express, ServerOptions} from './src/main/server/express';
import * as http from 'http';
const options = {
static: process.env.DEVMIND_SITE_PATH || `build/dist`,
port: process.env.PORT || 8080,
mongodb: {
url: process.env.DEVMIND_MONGO_URL || 'mongodb://localhost:27017/devminddb',
user: process.env.DEVMIND_MONGO_USER || 'devmind',
password: process.env.DEVMIND_MONGO_PASSWORD || 'pass'
},
mail: {
host: process.env.DEVMIND_MAIL_HOST || 'ssl0.ovh.net',
port: process.env.DEVMIND_MAIL_PORT ? parseInt(process.env.DEVMIND_MAIL_PORT) : 465,
secure: true,
user: process.env.DEVMIND_MAIL_USER,
password: process.env.DEVMIND_MAIL_PASSWORD
},
securedUrls: [
{url: '/users', right: 'ADMIN'},
{url: '/statistics', right: 'ADMIN'}
],
secret: process.env.DEVMIND_SESSION_SECRET || 'SMHQs7cLAC3x'
} as ServerOptions;
const server = Express.bootstrap(options).app;
http.createServer(server)
//listen on provided ports
.listen(options.port)
//add error handler
.on("error", (error: any) => {
if (error.syscall !== "listen") {
throw error;
}
switch (error.code) {
case "EACCES":
console.error(`${options.port} requires elevated privileges`);
process.exit(1);
break;
case "EADDRINUSE":
console.error(`${options.port} is already in use`);
process.exit(1);
break;
default:
throw error;
}
})
//start listening on port
.on("listening", () => {
console.debug('Listening on ' + options.port);
console.debug(`Environnement ${process.env.NODE_ENV}`);
});