-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (32 loc) · 939 Bytes
/
app.js
File metadata and controls
40 lines (32 loc) · 939 Bytes
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
"use strict";
require("dotenv").config();
let http = require("http");
let express = require("express");
let app = require("@root/async-router").Router();
if ("DEVELOPMENT" === process.env.ENV) {
// set special options
}
app.get("/hello", function (req, res) {
return { message: "Hello, World!" };
});
// TODO error handler for /api
app.use("/", function (err, req, res, next) {
if (err.code) {
res.statusCode = err.status || 500;
res.json({ status: err.status, code: err.code, message: err.message });
return;
}
console.error("Unexpected Error:");
console.error(err);
res.statusCode = 500;
res.end("Internal Server Error");
});
let server = express().use("/", app);
if (require.main === module) {
let port = process.env.PORT || 3042;
http.createServer(server).listen(port, function () {
/* jshint validthis:true */
console.info("Listening on", this.address());
});
}
module.exports = app;