-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
56 lines (45 loc) · 1.55 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
51
52
53
54
55
56
// Dotenv config
require("dotenv").config();
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
// Config cors
const cors = require("cors");
// Config mongoose
const mongoose = require("mongoose");
const db = process.env.DB || 'mongodb://localhost/panda-api';
mongoose
.connect(db, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then((x) => {
console.log(`Connected to Mongo! Database name: "${x.connections[0].name}"`);
})
.catch((err) => {
console.error("Error connecting to mongo", err);
});
const app = express();
app.use(cors({ origin: ['http://localhost:4444', 'https://pandafeed.netlify.app', 'https://pandafeed.co'], credentials: true }));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const usersRouter = require('./routes/user');
const companyRouter = require('./routes/company');
const changelogRouter = require('./routes/changelog');
const updatesRouter = require('./routes/update');
const boardRouter = require('./routes/board');
const postRouter = require('./routes/post');
const checkoutRouter = require('./routes/checkout');
app.use('/api/', usersRouter);
app.use('/api/', companyRouter);
app.use('/api/', changelogRouter);
app.use('/api/', updatesRouter);
app.use('/api/', boardRouter);
app.use('/api/', postRouter);
app.use('/api/', checkoutRouter);
module.exports = app;