-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (34 loc) · 1.13 KB
/
server.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
const express = require("express");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const path = require("path");
const cors = require("cors");
const passport = require("passport");
const dotEnv = require("dotenv");
dotEnv.config();
const app = express();
const profileRoute = require("./routes/profile");
const usersRouter = require("./routes/users");
const postRouter = require("./routes/post");
//Database 연결
require("./config/database");
//middle ware
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
// passport config
require('./config/passport')(passport);
app.use("/profile", profileRoute);
app.use("/users", usersRouter);
app.use("/post", postRouter);
// Server
if (process.env.NODE_ENV || "production" === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html')); // relative path
});
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(`server started at ${PORT}`));