박기홍

server finished

No preview for this file type
......@@ -7,6 +7,7 @@
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.10.14",
"nodemon": "^2.0.6"
......
const express = require('express');
const app = express();
// const cors = require('cors');
const port = 8000;
const mongoose = require('mongoose');
......@@ -7,6 +8,19 @@ const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
// app.use(cors());
// app.all('/*', function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
// next();
// });
// app.all('/*', function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
// next();
// });
const db = mongoose.connection;
db.on('error', console.error);
......@@ -15,6 +29,7 @@ db.once('open', function(){
console.log("Connected to mongod server");
});
const router = require('./router')(app);
......
......@@ -160,25 +160,36 @@ module.exports = function(app)
}
}
console.log(fight, detail, traffic, control, support, activity);
// console.log(fight, detail, traffic, control, support, activity);
const recommandedJob = await jobRecommend(fight, detail, traffic, control, support, activity);
// TODO : recommand job
// const jobList = await Job.find({high: recommandedJob}).exec();
const jobList = await Job.find({high: recommandedJob}).exec();
// const rand = Math.floor(Math.random() * jobList.length);
// const result = jobList[rand];
const rand = Math.floor(Math.random() * jobList.length);
const result = jobList[rand];
res.send(recommandedJob);
// res.send(result);
// res.send(recommandedJob);
res.send(result);
});
app.post('/addJobs', async(req, res, next) => {
// 보직 추가하는 api
const datas = req.body;
for(let i=0; i<datas.length; i++){
const data = new Job();
data.num = datas[i].num;
data.high = datas[i].high;
data.low = datas[i].low;
data.description = datas[i].description;
data.image = datas[i].image;
await data.save();
}
res.send(datas[0]);
});
app.post('/addQuestions', async(req, res, next) => {
// 질문 추가하는 api
......