김명주

Delete unnecessary file

1 -var key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjoiMjAxNjMxMTYzIiwiYXV0aF9pZCI6IjIiLCJ0b2tlbl90eXBlIjoiQWNjZXNzVG9rZW4iLCJzZXJ2aWNlX2lkIjoiNDMwMDExMzkzIiwiWC1BcHAtUmF0ZS1MaW1pdCI6IjUwMDoxMCIsIm5iZiI6MTYzNDMwMTE0NCwiZXhwIjoxNjQ5ODUzMTQ0LCJpYXQiOjE2MzQzMDExNDR9.EEWMly4HZG_DY-aleMtDFVOOmbWl8uVmG1tHVM3c-BE"
2 -var express = require('express');
3 -var app=express();
4 -
5 -const bodyParser=require('body-parser');
6 -const { fileURLToPath } = require('url');
7 -app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함
8 -app.use(bodyParser.json()); // json 타입으로 파싱하게 설정
9 -app.use('/inf/result',express.static('metadata'));
10 -app.use('/',express.static('views'));
11 -app.use('/game/result',express.static('metadata'));
12 -app.set('views', __dirname + '/views');
13 -app.set('view engine', 'ejs');
14 -
15 -var chname;
16 -var vec=[];
17 -
18 -app.post("/inf/result",(req,res)=>{
19 - chname=encodeURIComponent(req.body.test);
20 -});
21 -
22 -app.get("/inf/result",(req,res)=>{
23 - var api_url='https://api.nexon.co.kr/kart/v1.0/users/nickname/'+chname;
24 - var request=require('request');
25 - var options={
26 - url: api_url,
27 - headers:{Authorization: key}
28 - };
29 -
30 -
31 - request.get(options, function(error, response, body){
32 - if (!error && response.statusCode == 200) {
33 - var jsbody=JSON.parse(body);
34 - var option2={
35 - url: "https://api.nexon.co.kr/kart/v1.0/users/"+jsbody.accessId+"/matches?start_date=&end_date= &offset=0&limit=10&match_types=",
36 - headers:{Authorization: key}
37 - };
38 - request.get(option2, function(error, response, body){
39 - var match=JSON.parse(body);
40 - res.render('inf_search_result',{name: jsbody.name, level: jsbody.level,body:JSON.stringify(match)});
41 - });
42 - } else {
43 - res.status(response.statusCode).end();
44 - console.log('error = ' + response.statusCode);
45 - }
46 - });
47 -});
48 -
49 -app.post("/game/result",(req,res)=>{
50 - vec=req.body.test;
51 - var item=["empty", "추억", "empty", "신중함","안정적","empty","열정","책임감","아이템","스피드","믿음직","호기심","헌신적","자유로움"];
52 - keyword=[];
53 - for(var i=1; i<vec.length; i++){
54 - if(i%2!=0){
55 - if(vec[i]=="1"){
56 - keyword.push(item[i-1]);
57 - }
58 - else{
59 - keyword.push(item[i]);
60 - }
61 - }
62 - }
63 -})
64 -
65 -app.get("/game/result",(req,res)=>{
66 - var temp="";
67 - for(var i=0; i<vec.length; i++){
68 - if(i!=2 && i!=3 && i!=4 && i!=5 && i!=10 && i!=11)
69 - temp+=vec[i];
70 - }
71 - var fs=require('fs');
72 - var url="kart_find"+temp+"/";
73 - var testFolder="metadata/kart_find"+temp;
74 - fs.readdir(testFolder, function(error, list){
75 - var rand=Math.floor(Math.random()*list.length);
76 - res.render('game_result',{url:url,body:list[rand],keyword:keyword});
77 - });
78 -});
79 -
80 -app.get("/game",(req,res)=>{
81 - res.render('game_home');
82 -});
83 -app.get("/inf",(req,res)=>{
84 - res.render('inf_search_home');
85 -});
86 -
87 -app.get("/",(req,res)=>{
88 - res.render('main_home');
89 -});
90 -
91 -app.listen("8080",function(req,res){
92 - console.log('server listening at port no. 8080');
93 -});