-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
48 lines (40 loc) · 1.17 KB
/
server.ts
File metadata and controls
48 lines (40 loc) · 1.17 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Request, Response } from 'express';
const cors = require('cors');
const express = require('express');
const dotenv = require('dotenv');
const path = require('path');
dotenv.config({ path: './config/.env' });
const db = require('./config/db');
const signup = require('./routes/signup');
const auth = require('./routes/auth');
const randomnum = require('./routes/randomnum');
const scores = require('./routes/scores');
const app = express();
app.use(cors());
const PORT: String | Number = process.env.PORT || 5000;
// body parser middleware
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
// Routes
app.use('/api/signup', signup);
app.use('/api/auth', auth);
app.use('/api/scores', scores);
app.use('/api/randomnum', randomnum);
// Connecting to DB
db();
if (process.env.NODE_ENV === 'production') {
// setting the static folder for the deployment
app.use(express.static('client/build'));
app.get('*', (req: Request, res: Response) =>
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
);
}
// Server setup
app.listen(PORT, () => {
console.log(`The application is listening on port ${PORT}`);
});
module.exports = app;