-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (45 loc) · 1.24 KB
/
server.js
File metadata and controls
56 lines (45 loc) · 1.24 KB
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
require('dotenv').config();
import express from 'express';
import bodyParser from 'body-parser';
import passport from 'passport';
import mongoose from 'mongoose';
import cors from 'cors';
import morgan from 'morgan';
import { dbConnect } from './db-mongoose';
import { router as usersRouter } from './users';
import { router as documentsRouter } from './documents';
import { PORT, CLIENT_ORIGIN } from './config';
import { router as authRouter, localStrategy, jwtStrategy } from './auth';
import SIO from './lib/sio';
export const app = express();
mongoose.Promise = global.Promise;
// Logging
app.use(morgan('common'));
// CORS
app.use(
cors({ origin: CLIENT_ORIGIN, })
);
app.use(
bodyParser.json()
);
passport.use(localStrategy);
passport.use(jwtStrategy);
app.use('/users', usersRouter);
app.use('/auth', authRouter);
app.use('/documents', documentsRouter);
export const runServer = (port = PORT) => {
const server = app
.listen(port, () => {
console.info(`App listening on port ${server.address().port}`);
})
.on('error', (err) => {
console.error('Express failed to start');
console.error(err);
});
const sio = new SIO(server);
sio.connect();
};
if (require.main === module) {
dbConnect();
runServer();
}