김명주

Split main js file

var express = require('express');
var app=express();
var test=require('./test.js');
var search=require('./search.js');
const bodyParser=require('body-parser');
app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함
app.use(bodyParser.json()); // json 타입으로 파싱하게 설정
app.use('/',express.static('views'));
app.use('/test/result',express.static('views'));
app.use('/search/result',express.static('views'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
/* kart recommendation */
app.get('/test',test.home_get);
app.get('/test/result',test.result_get);
app.post('/test/result',test.result_post);
/* inf */
app.get('/search',search.home_get);
app.get('/search/result',search.result_get);
app.post('/search/result',search.result_post);
/* home page */
app.get("/",(req,res)=>{
res.render('main_home');
});
/* server */
app.listen("8080",function(req,res){
console.log('server listening at port no. 8080');
});
var vec;
var keyword=[];
exports.home_get=function(req,res){
res.render('test_home');
};
exports.result_get=function(req,res){
var temp="";
for(var i=0; i<vec.length; i++){
if(i!=2 && i!=3 && i!=4 && i!=5 && i!=10 && i!=11)
temp+=vec[i];
}
var fs=require('fs');
var url="metadata/kart_find"+temp+"/";
var testFolder="views/metadata/kart_find"+temp;
fs.readdir(testFolder, function(error, list){
var rand=Math.floor(Math.random()*list.length);
res.render('test_result',{url:url,body:list[rand],keyword:keyword});
});
};
exports.result_post=function(req,res){
vec=req.body.test;
var item=["empty", "추억", "empty", "신중함","안정적","empty","열정","책임감","아이템","스피드","믿음직","호기심","헌신적","자유로움"];
keyword=[];
for(var i=1; i<vec.length; i++){
if(i%2!=0){
if(vec[i]=="1"){
keyword.push(item[i-1]);
}
else{
keyword.push(item[i]);
}
}
}
};
\ No newline at end of file