오수빈

Merge branch 'subin'

......@@ -6,6 +6,7 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
//var categoryRouter = require('./routes/category');
var categoryRouter = require('./routes/category');
var app = express();
......
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [0.2.1](https://github.com/Gozala/querystring/compare/v0.2.0...v0.2.1) (2021-02-15)
_Maintanance update_
## [0.2.0] - 2013-02-21
### Changed
- Refactor into function per-module idiomatic style.
- Improved test coverage.
## [0.1.0] - 2011-12-13
### Changed
- Minor project reorganization
## [0.0.3] - 2011-04-16
### Added
- Support for AMD module loaders
## [0.0.2] - 2011-04-16
### Changed
- Ported unit tests
### Removed
- Removed functionality that depended on Buffers
## [0.0.1] - 2011-04-15
### Added
- Initial release
Copyright 2012 Irakli Gozalishvili
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# querystring
[![NPM](https://img.shields.io/npm/v/querystring.svg)](https://npm.im/querystring)
[![gzip](https://badgen.net/bundlephobia/minzip/querystring@latest)](https://bundlephobia.com/result?p=querystring@latest)
Node's querystring module for all engines.
_If you want to help with evolution of this package, please see https://github.com/Gozala/querystring/issues/20 PR's welcome!_
## 🔧 Install
```sh
npm i querystring
```
## 📖 Documentation
Refer to [Node's documentation for `querystring`](https://nodejs.org/api/querystring.html).
## 📜 License
MIT © [Gozala](https://github.com/Gozala)
/**
* parses a URL query string into a collection of key and value pairs
*
* @param qs The URL query string to parse
* @param sep The substring used to delimit key and value pairs in the query string
* @param eq The substring used to delimit keys and values in the query string
* @param options.decodeURIComponent The function to use when decoding percent-encoded characters in the query string
* @param options.maxKeys Specifies the maximum number of keys to parse. Specify 0 to remove key counting limitations default 1000
*/
export type decodeFuncType = (
qs?: string,
sep?: string,
eq?: string,
options?: {
decodeURIComponent?: Function;
maxKeys?: number;
}
) => Record<any, unknown>;
export default decodeFuncType;
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
module.exports = function(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
} else if (Array.isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
};
/**
* It serializes passed object into string
* The numeric values must be finite.
* Any other input values will be coerced to empty strings.
*
* @param obj The object to serialize into a URL query string
* @param sep The substring used to delimit key and value pairs in the query string
* @param eq The substring used to delimit keys and values in the query string
* @param name
*/
export type encodeFuncType = (
obj?: Record<any, unknown>,
sep?: string,
eq?: string,
name?: any
) => string;
export default encodeFuncType;
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
var stringifyPrimitive = function(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
};
module.exports = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
if (obj === null) {
obj = undefined;
}
if (typeof obj === 'object') {
return Object.keys(obj).map(function(k) {
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (Array.isArray(obj[k])) {
return obj[k].map(function(v) {
return ks + encodeURIComponent(stringifyPrimitive(v));
}).join(sep);
} else {
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
}
}).filter(Boolean).join(sep);
}
if (!name) return '';
return encodeURIComponent(stringifyPrimitive(name)) + eq +
encodeURIComponent(stringifyPrimitive(obj));
};
import decodeFuncType from "./decode";
import encodeFuncType from "./encode";
export const decode: decodeFuncType;
export const parse: decodeFuncType;
export const encode: encodeFuncType;
export const stringify: encodeFuncType;
'use strict';
exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');
{
"_from": "querystring",
"_id": "querystring@0.2.1",
"_inBundle": false,
"_integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==",
"_location": "/querystring",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "querystring",
"name": "querystring",
"escapedName": "querystring",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz",
"_shasum": "40d77615bb09d16902a85c3e38aa8b5ed761c2dd",
"_spec": "querystring",
"_where": "C:\\Users\\se051\\OneDrive\\바탕 화면\\나의 대학라이프\\오픈소스SW개발\\텀프\\animal-Info",
"author": {
"name": "Irakli Gozalishvili",
"email": "rfobic@gmail.com"
},
"bugs": {
"url": "http://github.com/Gozala/querystring/issues/"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Node's querystring module for all engines.",
"devDependencies": {
"retape": "~0.x.0",
"tape": "~0.1.5",
"test": "~0.x.0"
},
"engines": {
"node": ">=0.4.x"
},
"homepage": "https://github.com/Gozala/querystring#readme",
"id": "querystring",
"keywords": [
"commonjs",
"query",
"querystring"
],
"license": "MIT",
"main": "index.js",
"name": "querystring",
"repository": {
"type": "git",
"url": "git://github.com/Gozala/querystring.git",
"web": "https://github.com/Gozala/querystring"
},
"scripts": {
"test": "npm run test-node && npm run test-tap",
"test-node": "node ./test/common-index.js",
"test-tap": "node ./test/tap-index.js"
},
"version": "0.2.1"
}
1.1.0 / 2015-08-14
==================
* fix typo
* feat: Support IE8
1.0.1 / 2015-07-06
==================
* refactor: add \n to benchmark
* fix '\n' encoding
1.0.0 / 2015-04-04
==================
* deps: upgrade iconv-lite to 0.4.7
0.2.0 / 2014-04-25
==================
* urlencode.stringify done (@alsotang)
0.1.2 / 2014-04-09
==================
* remove unused variable QueryString (@azbykov)
0.1.1 / 2014-02-25
==================
* improve parse() performance 10x
0.1.0 / 2014-02-24
==================
* decode with charset
* add npm image
* remove 0.6 for travis
* update to support coveralls
* use jscover instead of jscoverage
* update gitignore
* Merge pull request #1 from aleafs/master
* Add http entries test case
0.0.1 / 2012-10-31
==================
* encode() done. add benchmark and tests
* Initial commit
This software is licensed under the MIT License.
Copyright (C) 2012 - 2014 fengmk2 <fengmk2@gmail.com>
Copyright (C) 2015 node-modules
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
urlencode [![Build Status](https://secure.travis-ci.org/node-modules/urlencode.png)](http://travis-ci.org/node-modules/urlencode) [![Coverage Status](https://coveralls.io/repos/node-modules/urlencode/badge.png)](https://coveralls.io/r/node-modules/urlencode)
=======
[![NPM](https://nodei.co/npm/urlencode.png?downloads=true&stars=true)](https://nodei.co/npm/urlencode/)
encodeURIComponent with charset, e.g.: `gbk`
## Install
```bash
$ npm install urlencode
```
## Usage
```js
var urlencode = require('urlencode');
console.log(urlencode('苏千')); // default is utf8
console.log(urlencode('苏千', 'gbk')); // '%CB%D5%C7%A7'
// decode gbk
urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千'
// parse gbk querystring
urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'}
// stringify obj with gbk encoding
var str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5
var obj = {'x' : {'y' : [{'v' : {'w' : '雾空'}}]}};
urlencode.stringify(obj, {charset: 'gbk'}).should.equal(str);
```
## Benchmark
### urlencode(str, encoding)
```bash
$ node benchmark/urlencode.js
node version: v0.10.26
urlencode(str) x 11,980 ops/sec ±1.13% (100 runs sampled)
urlencode(str, "gbk") x 8,575 ops/sec ±1.58% (94 runs sampled)
encodeURIComponent(str) x 11,677 ops/sec ±2.32% (93 runs sampled)
Fastest is urlencode(str)
```
### urlencode.decode(str, encoding)
```bash
$ node benchmark/urlencode.decode.js
node version: v0.10.26
urlencode.decode(str) x 26,027 ops/sec ±7.51% (73 runs sampled)
urlencode.decode(str, "gbk") x 14,409 ops/sec ±1.72% (98 runs sampled)
decodeURIComponent(str) x 36,052 ops/sec ±0.90% (96 runs sampled)
urlencode.parse(qs, {charset: "gbk"}) x 16,401 ops/sec ±1.09% (98 runs sampled)
urlencode.parse(qs, {charset: "utf8"}) x 23,381 ops/sec ±2.22% (93 runs sampled)
Fastest is decodeURIComponent(str)
```
## TODO
* [x] stringify()
## License
[MIT](LICENSE.txt)
/**!
* urlencode - lib/urlencode.js
*
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
*/
"use strict";
/**
* Module dependencies.
*/
var iconv = require('iconv-lite');
function isUTF8(charset) {
if (!charset) {
return true;
}
charset = charset.toLowerCase();
return charset === 'utf8' || charset === 'utf-8';
}
function encode(str, charset) {
if (isUTF8(charset)) {
return encodeURIComponent(str);
}
var buf = iconv.encode(str, charset);
var encodeStr = '';
var ch = '';
for (var i = 0; i < buf.length; i++) {
ch = buf[i].toString('16');
if (ch.length === 1) {
ch = '0' + ch;
}
encodeStr += '%' + ch;
}
encodeStr = encodeStr.toUpperCase();
return encodeStr;
}
function decode(str, charset) {
if (isUTF8(charset)) {
return decodeURIComponent(str);
}
var bytes = [];
for (var i = 0; i < str.length; ) {
if (str[i] === '%') {
i++;
bytes.push(parseInt(str.substring(i, i + 2), 16));
i += 2;
} else {
bytes.push(str.charCodeAt(i));
i++;
}
}
var buf = new Buffer(bytes);
return iconv.decode(buf, charset);
}
function parse(qs, sep, eq, options) {
if (typeof sep === 'object') {
// parse(qs, options)
options = sep;
sep = null;
}
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
var charset = null;
if (options) {
if (typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
if (typeof options.charset === 'string') {
charset = options.charset;
}
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20');
var idx = x.indexOf(eq);
var kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
if (kstr && kstr.indexOf('%') >= 0) {
try {
k = decode(kstr, charset);
} catch (e) {
k = kstr;
}
} else {
k = kstr;
}
if (vstr && vstr.indexOf('%') >= 0) {
try {
v = decode(vstr, charset);
} catch (e) {
v = vstr;
}
} else {
v = vstr;
}
if (!has(obj, k)) {
obj[k] = v;
} else if (Array.isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
}
function has(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
function isASCII(str) {
return (/^[\x00-\x7F]*$/).test(str);
}
function encodeComponent(item, charset) {
item = String(item);
if (isASCII(item)) {
item = encodeURIComponent(item);
} else {
item = encode(item, charset);
}
return item;
}
var stringify = function(obj, prefix, options) {
if (typeof prefix !== 'string') {
options = prefix || {};
prefix = null;
}
var charset = options.charset || 'utf-8';
if (Array.isArray(obj)) {
return stringifyArray(obj, prefix, options);
} else if ('[object Object]' === {}.toString.call(obj)) {
return stringifyObject(obj, prefix, options);
} else if ('string' === typeof obj) {
return stringifyString(obj, prefix, options);
} else {
return prefix + '=' + encodeComponent(String(obj), charset);
}
};
function stringifyString(str, prefix, options) {
if (!prefix) {
throw new TypeError('stringify expects an object');
}
var charset = options.charset;
return prefix + '=' + encodeComponent(str, charset);
}
function stringifyArray(arr, prefix, options) {
var ret = [];
if (!prefix) {
throw new TypeError('stringify expects an object');
}
for (var i = 0; i < arr.length; i++) {
ret.push(stringify(arr[i], prefix + '[' + i + ']', options));
}
return ret.join('&');
}
function stringifyObject(obj, prefix, options) {
var ret = [];
var keys = Object.keys(obj);
var key;
var charset = options.charset;
for (var i = 0, len = keys.length; i < len; ++i) {
key = keys[i];
if ('' === key) {
continue;
}
if (null === obj[key]) {
ret.push(encode(key, charset) + '=');
} else {
ret.push(stringify(
obj[key],
prefix ? prefix + '[' + encodeComponent(key, charset) + ']': encodeComponent(key, charset),
options));
}
}
return ret.join('&');
}
module.exports = encode;
module.exports.encode = encode;
module.exports.decode = decode;
module.exports.parse = parse;
module.exports.stringify = stringify;
{
"_from": "urlencode@^1.1.0",
"_id": "urlencode@1.1.0",
"_inBundle": false,
"_integrity": "sha1-HyuibwE8hfATP3o61v8nMK33y7c=",
"_location": "/urlencode",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "urlencode@^1.1.0",
"name": "urlencode",
"escapedName": "urlencode",
"rawSpec": "^1.1.0",
"saveSpec": null,
"fetchSpec": "^1.1.0"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/urlencode/-/urlencode-1.1.0.tgz",
"_shasum": "1f2ba26f013c85f0133f7a3ad6ff2730adf7cbb7",
"_spec": "urlencode@^1.1.0",
"_where": "C:\\Users\\se051\\OneDrive\\바탕 화면\\나의 대학라이프\\오픈소스SW개발\\텀프\\animal-Info",
"author": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"bugs": {
"url": "https://github.com/node-modules/urlencode/issues"
},
"bundleDependencies": false,
"dependencies": {
"iconv-lite": "~0.4.11"
},
"deprecated": false,
"description": "encodeURIComponent with charset",
"devDependencies": {
"autod": "*",
"beautify-benchmark": "*",
"benchmark": "*",
"blanket": "*",
"contributors": "*",
"istanbul": "~0.3.17",
"jshint": "*",
"mocha": "*",
"should": "7"
},
"files": [
"lib"
],
"homepage": "https://github.com/node-modules/urlencode",
"keywords": [
"urlencode",
"urldecode",
"encodeURIComponent",
"decodeURIComponent",
"querystring",
"parse"
],
"license": "MIT",
"main": "lib/urlencode.js",
"name": "urlencode",
"repository": {
"type": "git",
"url": "git://github.com/node-modules/urlencode.git"
},
"scripts": {
"autod": "autod -w --prefix '~' -t test -e examples",
"benchmark": "node benchmark/urlencode.js && node benchmark/urlencode.decode.js",
"cnpm": "npm install --registry=https://registry.npm.taobao.org",
"jshint": "jshint .",
"test": "mocha -R spec -t 20000 -r should test/*.test.js",
"test-cov": "istanbul cover node_modules/.bin/_mocha -- -t 20000 -r should test/*.test.js",
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- -t 20000 -r should test/*.test.js"
},
"version": "1.1.0"
}
......@@ -534,6 +534,11 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
},
"querystring": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz",
"integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg=="
},
"range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
......@@ -693,6 +698,14 @@
"punycode": "^2.1.0"
}
},
"urlencode": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/urlencode/-/urlencode-1.1.0.tgz",
"integrity": "sha1-HyuibwE8hfATP3o61v8nMK33y7c=",
"requires": {
"iconv-lite": "~0.4.11"
}
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
......
......@@ -14,7 +14,9 @@
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"querystring": "^0.2.1",
"request": "^2.88.2",
"urlencode": "^1.1.0",
"xml-js": "^1.6.11",
"xml2js": "^0.4.23"
}
......
......@@ -3,6 +3,7 @@ var router = express.Router();
var request = require('request');
const convert = require('xml-js');
require('dotenv').config();
var urlencode = require('urlencode');
/* GET home page. */
let GU_CODE;
......@@ -10,17 +11,28 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY;
let user_gu;
let user_latitude;
let user_longitude;
let hospital_list = [];
router.get('/hospital', function (req, res) {
router.post('/hospital', function(req, res){
//gu 받아오기
var body = req.body;
var gu_select = body.user_gu;
var menu = '동물병원';
// encoding for url
var menu_encode = urlencode(menu);
var gu_select_encode = urlencode(gu_select);
//api
let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=%EB%8F%99%EB%AC%BC%EB%B3%91%EC%9B%90&where=%EA%B0%95%EB%B6%81%EA%B5%AC`;
let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`;
request(pet_url, function(err, response, body){
if(err) {
console.log(`err => ${err}`)
}
else {
if(res.statusCode == 200) {
var hospital_list = []; //얘를 전역으로 선언해서 중복이 발생했던 거였어요 ㅠ
var titles = '';
var result = convert.xml2json(body, {compact: true, spaces: 4});
var petJson = JSON.parse(result)
var itemList = petJson.response.body.items;
......@@ -33,14 +45,13 @@ router.get('/hospital', function (req, res) {
}
//테스트용 console.log
var titles = '';
for(i=0; i<hospital_list.length; i++){
titles = titles+hospital_list[i].title._text+'\n';
}
console.log(titles);
}
}
res.send("finish");
res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
})
});
......
......@@ -65,6 +65,14 @@
font-size: xx-large;
}
</style>
<script>
function sm() {
document.getElementById("location").submit();
}
</script>
</head>
<body>
......@@ -83,9 +91,13 @@
<p>
지역 선택
</p>
<select>
<form action="/category/hospital" method="post" name="location" id="location">
<select onchange="sm()" name="user_gu" id="user_gu_select">
<option value='' selected="true" disabled="true">--Please choose an option--</option>
<option value='금천구'>금천구</option>
<option value='강남구'>강남구</option>
</select>
</form>
</div>
</div>
......
<body>
<%- include(`results/${category}`) -%>
</body>
\ No newline at end of file
it's hospital page
\ No newline at end of file