-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (29 loc) · 951 Bytes
/
app.js
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
const express = require("express");
const app = express();
const cors = require("cors");
const morgan = require("morgan");
const args = process.argv.slice(2);
const routes = require("./routes");
const { logStack } = require("./utils/helpers");
require("dotenv").config();
const port = process.env.PORT || 3000;
const env = process.env.NODE_ENV || "production";
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan(env == "development" ? "dev" : "tiny"));
app.use("/api", routes);
app.get("/", (req, res) => {
res.status(200).json(logStack(app._router.stack));
});
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});
// Initialize ngrok if requested
if (args.includes("ngrok")) {
const ngrok = require("ngrok");
ngrok
.connect(port)
.then(url => console.log(`Tunnel created at: ${url}`))
.catch(err => console.error(err));
}