-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
82 lines (57 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const app = express();
const router = express.Router();
const mongoose = require('mongoose');
const db = require("./config/keys").mongoURI;
const users = router.use(require('./routes/api/users'));
const memes = router.use(require('./routes/api/memes'));
// const User = require('./models/User');
// const Meme = require('./models/Meme');
const bodyParser = require('body-parser');
const passport = require('passport');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", req.header('Origin'));
res.header("Access-Control-Allow-Credentials", true);
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
next();
});
app.use(passport.initialize());
require('./config/passport')(passport);
const path = require('path');
if (process.env.NODE_ENV === 'production') {
app.use(express.static('frontend/build'));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'));
})
}
mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log("Connected to MongoDB"))
.catch(err => console.log(err));
app.use(bodyParser.urlencoded({
extended: false
}));
// app.use(bodyParser.json());
app.use(bodyParser.json({limit: '100mb'}))
app.get("/", (req, res) => {
res.send("Hello world~~~ root page");
});
app.get("/createMeme", (req, res) => {
res.send("modal to create meme");
});
app.get("/login", (req, res) => {
res.send("modal to login users");
});
app.get("/signup", (req, res) => {
res.send("modal to signup users");
});
app.use('/api/users', users);
app.use('/api/memes', memes);
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Backend listening on port: ${port}`)
})