-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (37 loc) · 1.2 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const cors = require('cors');
const connect = require('./db/connect')
const routerTeam = require('./router/teamRoute')
const routerRegistration = require('./router/registrationRoute')
const app = express();
const port = process.env.PORT || 8080;
/** middleware */
// app.use(express.json())
// app.use(express.urlencoded({ extended: false }))
app.use(express.json({ limit: '100mb' }));
app.use(cors())
app.disable('x-powered-by')
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
});
/** API Routes */
app.use('/api', routerRegistration, routerTeam)
/** http get request */
app.get('/', (req, res) => {
res.status(201).send('Hello World!')
})
/** start server */
connect().then(() => {
try {
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})
} catch (error) {
console.log("Cannot connect with server");
}
}).catch((error) => {
console.log("Database not connected");
})