-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserver.ts
46 lines (37 loc) · 1.23 KB
/
server.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
// Load .env file
import Sentry = require("@sentry/node");
import bodyParser from "body-parser";
require("dotenv").config();
import express, { Application, Request, Response } from "express";
import path = require("path");
import apiRouter from "./api/api";
import { initialiseLogging } from "./api/logging";
import { initialise } from "./google-sheets/sheets";
Sentry.init({
dsn: "https://[email protected]/1836276"
});
const app: Application = express();
// Production port or port 5000
const port = process.env.PORT || 5000;
// Sentry request handler
app.use(Sentry.Handlers.requestHandler());
// Set up to serve static files
app.use(express.static("client/build"));
// Parse application/json
app.use(bodyParser.json());
// Initialise Google Sheets API (to access sponsor list)
initialise();
// Serves the React build
app.get("/", (req: Request, res: Response) =>
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"))
);
// Set up logging
initialiseLogging(app);
// Routes requests to /api/
app.use("/api/", apiRouter);
// Set up sentry error monitoring
app.use(Sentry.Handlers.errorHandler());
// Listen on port
app.listen(port, () => {
console.log(`Express server initialised on port ${port}`);
});