-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
65 lines (58 loc) · 1.38 KB
/
index.ts
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
/**
* index.ts
* Bootstrap Node Express server.
*/
import * as express from 'express';
import {Log, HTTPLog} from "./util/logger";
import {Environment} from "./util/env";
import {Snappy} from "./service/snappy";
import {ping} from "./handler/ping";
import {snap} from "./handler/snap";
import {getErrorMessage} from "./util/error";
const app = express(),
emoji = require('node-emoji'),
welcome = require('cli-welcome');
/**
* VERSION is the current version number of Snappy.
* @type {string}
*/
const VERSION = '1.0';
/**
* Middleware
*/
app.use(HTTPLog);
/**
* Bootstrap routes.
*/
app.get('/snap', snap);
app.get('/ping', ping);
/**
* Prevent GET /favicon.ico.
*/
app.get('/favicon.ico', (req: express.Request, res: express.Response) => res.status(204));
/**
* Print Welcome Message.
*/
welcome({
title: `${emoji.get('camera_with_flash')} Snappy`,
tagLine: `by Ainsley Clark`,
bgColor: `#F15A29`,
color: `#000000`,
bold: true,
clear: true,
version: VERSION,
});
/**
* Wait for Snappy to load and start the server on the port
* specified in the env file.
*/
Snappy.ready
.then(() => {
const port = Environment.appPort || 3000;
app.listen(port, () => {
Log.info(`${emoji.get('camera_with_flash')} Snappy is listening on port ${port}`);
});
})
.catch(err => {
Log.error(getErrorMessage(err));
});