-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
62 lines (52 loc) · 1.55 KB
/
App.js
File metadata and controls
62 lines (52 loc) · 1.55 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
57
58
59
60
61
62
require('dotenv').config();
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const port = 5000;
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const notificationRouter = require('./routes/notifications.route');
const userRouter = require('./routes/users.route');
const workshopRouter = require('./routes/workshop.route');
const authRouter = require('./routes/auth.route');
process.on('unhandledRejection', (error) => {
console.error('unhandledRejection', JSON.stringify(error), error.stack);
process.exit(1);
});
process.on('uncaughtException', (error) => {
console.log('uncaughtException', JSON.stringify(error), error.stack);
process.exit(1);
});
process.on('beforeExit', () => {
app.close((err) => {
if (err) console.error(JSON.stringify(err), err.stack);
});
});
process.on('SIGINT', function () {
db.stop(function (err) {
process.exit(err ? 1 : 0);
});
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(
cors({
credentials: true,
origin: process.env.CLIENT_PUBLIC_URL || 'http://localhost:3000',
})
);
app.use(morgan('dev'));
app.use('/notifications', notificationRouter);
app.use('/users', userRouter);
app.use('/workshops', workshopRouter);
app.use('/auth', authRouter);
console.log('NODE_ENV', process.env.NODE_ENV);
app.listen(port, (err) => {
if (err) {
console.log(err);
} else {
console.log(`The app is running at ${port}`);
}
});