-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
33 lines (27 loc) · 831 Bytes
/
server.ts
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
require('dotenv').config();
import mongoose from "mongoose";
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import expressSession from "express-session";
import buildRoutes from "./src/routes";
let app = express();
app.use(cors());
app.use(cookieParser());
app.use(bodyParser.json());
app.use(expressSession({ secret: 'fotchKeaf' }));
app = buildRoutes(app);
const port = process.env.PORT || 3000;
function listen() {
app.listen(port);
console.log('Express app started on port ' + port);
}
function connect() {
mongoose.connection
.on('error', console.log)
.on('disconnected', connect)
.once('open', listen);
return mongoose.connect(process.env.MONGODB_URL, { keepAlive: true, useNewUrlParser: true });
}
connect();