-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.08 KB
/
index.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
40
41
42
/* DEPENDENCIES */
const express = require('express');
const app = express();
const cors = require("cors");
const path = require("path");
/* ENVIRONMENTAL VARIABLES */
const PORT = process.env.PORT || 5000;
/* CORS SECURITY - MIDDLE MAN */
app.use(cors());
app.use(express.json());
/* STATIC CONTENT */
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "app/build")));
}
/* ROUTE MAPPER */
const companiesRouter = require('./backend/routes/companies');
const logsRouter = require('./backend/routes/logs');
const analyticsRouter = require('./backend/routes/analytics');
const ticketsRouter = require('./backend/routes/tickets');
/* ROUTER STACK */
app.use('/api/v1/companies', companiesRouter);
app.use('/api/v1/logs', logsRouter);
app.use('/api/v1/analytics', analyticsRouter);
app.use('/api/v1/tickets', ticketsRouter);
/*
* CATCH ALL
* => Very important so that users don't go browsing around.
*/
app.get("*", (req, res) => {
res.json("Invalid/url");
});
/* MAIN */
app.listen(PORT, () => {
console.log(`server has started on port ${PORT}`);
});