Showing
1 changed file
with
43 additions
and
0 deletions
inf_search.js
0 → 100644
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 | +app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함 | ||
7 | +app.use(bodyParser.json()); // json 타입으로 파싱하게 설정 | ||
8 | + | ||
9 | +app.set('views', __dirname + '/views'); | ||
10 | +app.set('view engine', 'ejs'); | ||
11 | + | ||
12 | +var chname; | ||
13 | +app.post("/inf/result",(req,res)=>{ | ||
14 | + chname=encodeURIComponent(req.body.test); | ||
15 | +}); | ||
16 | + | ||
17 | +app.get("/inf/result",(req,res)=>{ | ||
18 | + var api_url='https://api.nexon.co.kr/kart/v1.0/users/nickname/'+chname; | ||
19 | + var request=require('request'); | ||
20 | + var options={ | ||
21 | + url: api_url, | ||
22 | + headers:{Authorization: key} | ||
23 | + }; | ||
24 | + | ||
25 | + request.get(options, function(error, response, body){ | ||
26 | + if (!error && response.statusCode == 200) { | ||
27 | + var jsbody=JSON.parse(body); | ||
28 | + //res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); and res.end(body) | ||
29 | + res.render('inf_search_result', {aid:jsbody.accessId, name: jsbody.name, level: jsbody.level}); | ||
30 | + } else { | ||
31 | + res.status(response.statusCode).end(); | ||
32 | + console.log('error = ' + response.statusCode); | ||
33 | + } | ||
34 | + }); | ||
35 | +}); | ||
36 | + | ||
37 | +app.get("/inf",(req,res)=>{ | ||
38 | + res.render('inf_search_home'); | ||
39 | +}); | ||
40 | + | ||
41 | +app.listen(8080,function(req,res){ | ||
42 | + console.log('server listening at port no. 8080'); | ||
43 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment