-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
29 lines (23 loc) · 1.03 KB
/
main.ts
File metadata and controls
29 lines (23 loc) · 1.03 KB
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
import express, { Application } from 'express';
import cors from 'cors';
import { routes as rtSecrets } from './api/secrets.js';
import accessPolicy from './accessPolicy.js';
export const server: Application = express();
/* Configure Express app built-in settings
https://expressjs.com/en/api.html#app.settings.table */
server.enable('case sensitive routing');
// Use cors() with no arguments to allow all origins
server.use(cors({
origin: import.meta.env.VITE_FRONTEND
}));
/* Prevent direct connections to the server using custom middleware.
It's important to put custom middleware after .use(cors()) is called since cors-related
headers don't seem to persist when each middleware function passes the request onto the
next one with next() */
if (import.meta.env.PROD) {server.use(accessPolicy)}
server.all('/', (req, res) => {res.sendStatus(400);});
server.use(rtSecrets);
if (import.meta.env.PROD) {
console.log(`\nListening on ${import.meta.env.VITE_HOST}:${import.meta.env.VITE_PORT}\n`)
server.listen(import.meta.env.VITE_PORT)
}