오윤석

character code 받아오는 api

......@@ -6,6 +6,6 @@ let routes = require('./routes');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/api/home', routes.home);
app.get('/api/character', routes.character.getCharacter);
let server = app.listen(80);
\ No newline at end of file
......
......@@ -84,6 +84,14 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
......@@ -444,6 +452,24 @@
"unpipe": "~1.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
......
......@@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"express": "^4.17.1",
"http": "0.0.1-security",
"nodemon": "^2.0.4"
......
axios = require('axios');
const crwalCharacterCode = async function(nickname) {
try {
const resp = await axios.get("https://maplestory.nexon.com/Ranking/World/Total?c=" + encodeURI(nickname));
const regex = new RegExp(`<dt><a href=\\"\\/Common\\/Character\\/Detail\\/[^\\?]+?\\?p=(.+?)\\"\\s+target=.+?\\/>${nickname}<\\/a><\\/dt>`);
const regexResult = regex.exec(resp.data);
if (!regexResult)
return false;
return regexResult[1];
} catch (error) {
console.log(error);
return false;
}
}
module.exports = {
getCharacter: async function(req, res) {
if (!req.query.nickname) {
res.status(204).send();
return;
}
const nickname = req.query.nickname;
const characterCode = await crwalCharacterCode(req.query.nickname);
if (!characterCode) {
res.status(404).send();
return;
}
console.log(characterCode);
res.send({ text: characterCode });
}
};
\ No newline at end of file
module.exports = function(req, res) {
res.send('this is home');
}
\ No newline at end of file
let routes = {};
routes.home = require('./home');
routes.character = require('./character');
module.exports = routes;
\ No newline at end of file
......