김명주

Split main js file

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