-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (54 loc) · 1.63 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
54
55
56
57
58
59
60
61
62
63
64
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv'
import mongoose from 'mongoose'
import morgan from 'morgan';
import users from './routes/users.js'
import auth from './routes/auth.js';
import words from './routes/words.js';
dotenv.config()
const app = express();
const port = process.env.PORT || 8000;
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200,
}
app.use(morgan("dev"))
app.use(express.json({ limit: "30mb", extended: true }));
app.use(express.urlencoded({ limit: "30mb", extended: true }));
app.use(cors(corsOptions))
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Credentials', true)
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT')
res.setHeader(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Origin, X-Auth-Token, X-JSON'
)
next();
})
const mongo_uri = process.env.DB_CONNECTION
mongoose.connect(mongo_uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
maxIdleTimeMS: 80000,
serverSelectionTimeoutMS: 80000,
socketTimeoutMS: 0,
connectTimeoutMS: 0
})
.then(() => {
console.log("Connected to Database")
})
.catch((err) => {
console.log(err)
process.exit()
});
app.get('/', (req, res) => {
res.send('Home')
})
app.use("/api/users", users)
app.use("/api/login", auth)
app.use("/api/words", words)
app.listen(port, () => {
console.log(`Server is started on ${port}`)
})