-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (66 loc) · 2.18 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// IMPORTS
require('dotenv').config();
require('aws-sdk/lib/maintenance_mode_message').suppress = true;
const express = require('express');
const cors = require('cors')
const app = express()
const mongoose = require('mongoose')
const cookieParser = require('cookie-parser')
var bodyParser = require('body-parser');
const vkApi = require('./middleware/vk-api')
const history = require('connect-history-api-fallback');
// IMPORT ROUTES
const userRouter = require('./routers/user-router')
const posterRouter = require('./routers/poster-router')
const eventLocationRouter = require('./routers/event-location-router')
const appStateRouter = require('./routers/app-state-router')
const priceRouter = require('./routers/price-router')
const eventLogRouter = require('./routers/event-log-router')
const ordRouter = require('./routers/ord-router')
const apiRouter = require('./routers/api-router')
const errorFilter = require('./exception/errorFilter');
// .USE
// app.use(history())
mongoose.set('strictQuery', true);
app.use(cors({
origin: [process.env.CLIENT_URL, "https://plpo.ru", "https://gorodaivesi.ru", "http://localhost:3030","http://afisha-hack.ru","https://afisha-hack.ru",],
credentials: true
}))
app.use(express.json())
app.use(cookieParser())
app.use(bodyParser.urlencoded({
extended: true
}));
// app.use(express.static('dist'))
// ROUTES
app.use('/auth', userRouter)
app.use('/poster', posterRouter)
app.use('/event-location', eventLocationRouter)
app.use('/app-state', appStateRouter)
app.use('/price', priceRouter)
app.use('/event-log', eventLogRouter)
app.use('/ord', ordRouter)
app.use('/api', apiRouter)
app.use(errorFilter)
// START SERVER
function startServer() {
try {
app.listen(process.env.PORT, () => { console.log(`Server is running on http://localhost:${process.env.PORT}`); })
} catch (err) {
console.error('Error while starting server: ', err);
}
}
function mongoConnect() {
mongoose.connect(process.env.MONGO_URL,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
)
const db = mongoose.connection;
db.once('open', function () {
console.log('connection')
});
}
startServer()
mongoConnect()