-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
35 lines (26 loc) · 964 Bytes
/
app.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
import express, { Application, urlencoded, json } from "express";
import { NextFunction, Request, Response } from "express";
import { resolve } from 'path';
import { config } from "dotenv";
import router from "./routes/routes";
if (process.env.NODE_ENV === 'testing') {
config({ path: './config/.test.env' });
} else if (process.env.NODE_ENV === 'development') {
config({ path: './config/.env' });
}
const app: Application = express();
app.use(json());
app.use(urlencoded({ extended: true }));
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.error(err.stack);
res.status(500).send('Something went wrong!!');
});
app.use("/api", router);
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req: Request, res: Response) => {
res.sendFile(resolve(__dirname, '..', 'client', 'build', 'index.html'));
});
}
export { app as default };