박기홍

server finished

No preview for this file type
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
7 "license": "MIT", 7 "license": "MIT",
8 "dependencies": { 8 "dependencies": {
9 "body-parser": "^1.19.0", 9 "body-parser": "^1.19.0",
10 + "cors": "^2.8.5",
10 "express": "^4.17.1", 11 "express": "^4.17.1",
11 "mongoose": "^5.10.14", 12 "mongoose": "^5.10.14",
12 "nodemon": "^2.0.6" 13 "nodemon": "^2.0.6"
......
1 const express = require('express'); 1 const express = require('express');
2 const app = express(); 2 const app = express();
3 +// const cors = require('cors');
3 const port = 8000; 4 const port = 8000;
4 5
5 const mongoose = require('mongoose'); 6 const mongoose = require('mongoose');
...@@ -7,6 +8,19 @@ const bodyParser = require('body-parser'); ...@@ -7,6 +8,19 @@ const bodyParser = require('body-parser');
7 8
8 app.use(bodyParser.urlencoded({extended:true})); 9 app.use(bodyParser.urlencoded({extended:true}));
9 app.use(bodyParser.json()); 10 app.use(bodyParser.json());
11 +// app.use(cors());
12 +
13 +// app.all('/*', function(req, res, next) {
14 +// res.header("Access-Control-Allow-Origin", "*");
15 +// res.header("Access-Control-Allow-Headers", "X-Requested-With");
16 +// next();
17 +// });
18 +
19 +// app.all('/*', function(req, res, next) {
20 +// res.header("Access-Control-Allow-Origin", "*");
21 +// res.header("Access-Control-Allow-Headers", "X-Requested-With");
22 +// next();
23 +// });
10 24
11 const db = mongoose.connection; 25 const db = mongoose.connection;
12 db.on('error', console.error); 26 db.on('error', console.error);
...@@ -15,6 +29,7 @@ db.once('open', function(){ ...@@ -15,6 +29,7 @@ db.once('open', function(){
15 console.log("Connected to mongod server"); 29 console.log("Connected to mongod server");
16 }); 30 });
17 31
32 +
18 const router = require('./router')(app); 33 const router = require('./router')(app);
19 34
20 35
......
...@@ -160,25 +160,36 @@ module.exports = function(app) ...@@ -160,25 +160,36 @@ module.exports = function(app)
160 } 160 }
161 } 161 }
162 162
163 - console.log(fight, detail, traffic, control, support, activity); 163 + // console.log(fight, detail, traffic, control, support, activity);
164 const recommandedJob = await jobRecommend(fight, detail, traffic, control, support, activity); 164 const recommandedJob = await jobRecommend(fight, detail, traffic, control, support, activity);
165 165
166 // TODO : recommand job 166 // TODO : recommand job
167 - // const jobList = await Job.find({high: recommandedJob}).exec(); 167 + const jobList = await Job.find({high: recommandedJob}).exec();
168 168
169 - // const rand = Math.floor(Math.random() * jobList.length); 169 + const rand = Math.floor(Math.random() * jobList.length);
170 - // const result = jobList[rand]; 170 + const result = jobList[rand];
171 171
172 - res.send(recommandedJob); 172 + // res.send(recommandedJob);
173 - // res.send(result); 173 + res.send(result);
174 174
175 }); 175 });
176 176
177 app.post('/addJobs', async(req, res, next) => { 177 app.post('/addJobs', async(req, res, next) => {
178 // 보직 추가하는 api 178 // 보직 추가하는 api
179 - 179 + const datas = req.body;
180 180
181 + for(let i=0; i<datas.length; i++){
182 + const data = new Job();
183 + data.num = datas[i].num;
184 + data.high = datas[i].high;
185 + data.low = datas[i].low;
186 + data.description = datas[i].description;
187 + data.image = datas[i].image;
188 +
189 + await data.save();
190 + }
181 191
192 + res.send(datas[0]);
182 }); 193 });
183 app.post('/addQuestions', async(req, res, next) => { 194 app.post('/addQuestions', async(req, res, next) => {
184 // 질문 추가하는 api 195 // 질문 추가하는 api
......