-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (41 loc) · 1.26 KB
/
app.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
const express = require('express');
const morgan = require('morgan');
const helmet = require('helmet');
const cors = require('cors');
const mongoose = require('mongoose');
const middleware = require('./middleware');
const adminRoutes = require('./api/routes/admin');
const tenantRoutes = require('./api/routes/tenant');
const stripeRoutes = require('./api/routes/stripe');
// Environment variables
require('dotenv').config();
// Init. Express app
const app = express();
// Check for local or remote db connection
const DATABASE_URL = process.env.LOCAL_DATABASE_URL || process.env.REMOTE_DATABASE_URL;
mongoose.connect(process.env.REMOTE_DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});
app.use(morgan('common'));
app.use(helmet());
app.use(cors({
origin: process.env.CORS_ORIGIN,
}));
app.use(express.json());
app.get('/', (req, res) => {
res.json({
message: 'Hello World!',
});
});
app.use('/api/admin', adminRoutes);
app.use('/api/tenant', tenantRoutes);
app.use('/api/stripe', stripeRoutes);
app.use(middleware.notFound);
app.use(middleware.errorHandler);
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});