-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
59 lines (48 loc) · 1.65 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
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const app = express();
//post 받아오기 위해 body-parser 사용
app.use(express.urlencoded({ extended: false }))
//react ajax 통신
app.use(express.json());
const cors = require('cors');
app.use(cors());
const path = require('path');
require('dotenv').config();
//swagger
const swaggerUi = require("swagger-ui-express");
const swaggerFile = require("./swagger-output");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerFile));
// DB connection
const id = process.env.DBid
const pwd = process.env.DBpwd
const url = process.env.url
// userId auto-increment
var autoIncrement = require('mongoose-auto-increment');
const mongoose = require("mongoose");
var connection = mongoose.connection;
mongoose.connect(`mongodb://${id}:${pwd}@${url}`, { useNewUrlParser: true, useUnifiedTopology: true }, function (err) {
if (err) {
console.error("mongoDB Connection Error!", err);
}
console.log("mongoDB Connected!");
// Server Open
app.listen(8080, function () {
console.log("Server listening on port 8080!");
});
});
autoIncrement.initialize(connection);
//router 사용
const studyRouter = require("./routes/study");
const studylistRouter =require("./routes/studylist");
app.use('/study', studyRouter);
app.use('/studylist',studylistRouter);
//react bulid
app.use(express.static(path.join(__dirname,'../build')))
app.get('/',function(req,res){
res.send(express.static(path.join(__dirname, '../build/index.html')));
})
// router 사용
const authRouter = require('./routes/auth');
app.use('/auth', authRouter);
const userRouter = require('./routes/users');
app.use('/users', userRouter);