김명주

Modify inf_search

connect game_home html and game_result html
...@@ -3,16 +3,18 @@ var express = require('express'); ...@@ -3,16 +3,18 @@ var express = require('express');
3 var app=express(); 3 var app=express();
4 4
5 const bodyParser=require('body-parser'); 5 const bodyParser=require('body-parser');
6 +const { fileURLToPath } = require('url');
6 app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함 7 app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함
7 app.use(bodyParser.json()); // json 타입으로 파싱하게 설정 8 app.use(bodyParser.json()); // json 타입으로 파싱하게 설정
8 app.use('/inf/result',express.static('metadata')); 9 app.use('/inf/result',express.static('metadata'));
9 app.use('/',express.static('views')); 10 app.use('/',express.static('views'));
10 - 11 +app.use('/game/result',express.static('metadata'));
11 app.set('views', __dirname + '/views'); 12 app.set('views', __dirname + '/views');
12 app.set('view engine', 'ejs'); 13 app.set('view engine', 'ejs');
13 14
14 var chname; 15 var chname;
15 var vec=[]; 16 var vec=[];
17 +
16 app.post("/inf/result",(req,res)=>{ 18 app.post("/inf/result",(req,res)=>{
17 chname=encodeURIComponent(req.body.test); 19 chname=encodeURIComponent(req.body.test);
18 }); 20 });
...@@ -65,18 +67,29 @@ app.get("/inf/result",(req,res)=>{ ...@@ -65,18 +67,29 @@ app.get("/inf/result",(req,res)=>{
65 } 67 }
66 }); 68 });
67 }); 69 });
68 -app.post("/game",(req,res)=>{ 70 +
69 - vec.push(req.body.test); 71 +app.post("/game/result",(req,res)=>{
70 - console.log(vec); 72 + vec=req.body.test;
71 }) 73 })
74 +
75 +app.get("/game/result",(req,res)=>{
76 + var fs=require('fs');
77 + var url="kart_special"+vec+"/";
78 + var testFolder="metadata/kart_special"+vec;
79 + fs.readdir(testFolder, function(error, list){
80 + var rand=Math.floor(Math.random()*list.length);
81 + res.render('game_result',{url:url,body:list[rand]});
82 + });
83 +});
84 +
72 app.get("/game",(req,res)=>{ 85 app.get("/game",(req,res)=>{
73 res.render('game_home'); 86 res.render('game_home');
74 -}) 87 +});
75 app.get("/inf",(req,res)=>{ 88 app.get("/inf",(req,res)=>{
76 res.render('inf_search_home'); 89 res.render('inf_search_home');
77 }); 90 });
78 91
79 -app.get("/",(req,res)=>{ 92 +app.get("/",(req,res)=>{
80 res.render('main_home'); 93 res.render('main_home');
81 }); 94 });
82 95
......