-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (40 loc) · 1.4 KB
/
index.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
import express from 'express';
import mongoose from 'mongoose';
import router from './router/router.js'
import fileUpload from 'express-fileupload'
import process from 'process';
import {dataBaseLogin, dataBasePassword} from "./config/database/config.js";
const PORT = 5000;
const DB_URL = `mongodb+srv://${dataBaseLogin}:${dataBasePassword}@cluster0.wmipr.mongodb.net/cart-db?retryWrites=true&w=majority`
const app = express();
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", req.headers.origin)
res.header("Access-Control-Allow-Credentials", "true")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", ["PUT", "DELETE"]);
next()
})
app.use( express.urlencoded( {
extended: true,
limit: '50mb'
} ) )
app.use(express.json({limit: '50mb', extended: true}));
app.use(fileUpload({}))
app.use('/static', express.static('static'));
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
});
app.use("/api", router)
const Start = async () => {
try {
await mongoose.connect(DB_URL, {
useUnifiedTopology: true,
useNewUrlParser: true
});
app.listen(PORT, () => console.log("Working"))
} catch (e) {
console.log(e)
console.log("Docker")
}
}
Start()