장주현

app.js 에postcode연결

1 +const express = require('express');
2 +const app = express();
3 +const PORT = process.env.PORT || 3000;
4 +
5 +//const indexRoute = require("./routes/index");
6 +
7 +app.set('views', __dirname + '/views');
8 +app.set('view engine', 'ejs');
9 +app.use(express.static(__dirname + '/public'));
10 +//var postcode = require(postcode.v2.html);
11 +//const fs = require('filesystem')
12 +
13 + app.get('/', function(req, res){
14 + //res.send('hello world');
15 + res.render('index');
16 + });
17 +
18 +//app.use('/', indexRoute);
19 +
20 +app.listen(PORT, function(){
21 + console.log('listen',PORT);
22 +});
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -11,11 +11,29 @@ ...@@ -11,11 +11,29 @@
11 "negotiator": "0.6.2" 11 "negotiator": "0.6.2"
12 } 12 }
13 }, 13 },
14 + "ansi-styles": {
15 + "version": "3.2.1",
16 + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
17 + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
18 + "requires": {
19 + "color-convert": "^1.9.0"
20 + }
21 + },
14 "array-flatten": { 22 "array-flatten": {
15 "version": "1.1.1", 23 "version": "1.1.1",
16 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 24 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
17 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 25 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
18 }, 26 },
27 + "async": {
28 + "version": "0.9.2",
29 + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
30 + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
31 + },
32 + "balanced-match": {
33 + "version": "1.0.0",
34 + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
35 + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
36 + },
19 "body-parser": { 37 "body-parser": {
20 "version": "1.19.0", 38 "version": "1.19.0",
21 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 39 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
...@@ -33,11 +51,48 @@ ...@@ -33,11 +51,48 @@
33 "type-is": "~1.6.17" 51 "type-is": "~1.6.17"
34 } 52 }
35 }, 53 },
54 + "brace-expansion": {
55 + "version": "1.1.11",
56 + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
57 + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
58 + "requires": {
59 + "balanced-match": "^1.0.0",
60 + "concat-map": "0.0.1"
61 + }
62 + },
36 "bytes": { 63 "bytes": {
37 "version": "3.1.0", 64 "version": "3.1.0",
38 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 65 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
39 "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 66 "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
40 }, 67 },
68 + "chalk": {
69 + "version": "2.4.2",
70 + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
71 + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
72 + "requires": {
73 + "ansi-styles": "^3.2.1",
74 + "escape-string-regexp": "^1.0.5",
75 + "supports-color": "^5.3.0"
76 + }
77 + },
78 + "color-convert": {
79 + "version": "1.9.3",
80 + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
81 + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
82 + "requires": {
83 + "color-name": "1.1.3"
84 + }
85 + },
86 + "color-name": {
87 + "version": "1.1.3",
88 + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
89 + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
90 + },
91 + "concat-map": {
92 + "version": "0.0.1",
93 + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
94 + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
95 + },
41 "content-disposition": { 96 "content-disposition": {
42 "version": "0.5.3", 97 "version": "0.5.3",
43 "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 98 "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
...@@ -84,6 +139,14 @@ ...@@ -84,6 +139,14 @@
84 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 139 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
85 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 140 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
86 }, 141 },
142 + "ejs": {
143 + "version": "3.1.3",
144 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.3.tgz",
145 + "integrity": "sha512-wmtrUGyfSC23GC/B1SMv2ogAUgbQEtDmTIhfqielrG5ExIM9TP4UoYdi90jLF1aTcsWCJNEO0UrgKzP0y3nTSg==",
146 + "requires": {
147 + "jake": "^10.6.1"
148 + }
149 + },
87 "encodeurl": { 150 "encodeurl": {
88 "version": "1.0.2", 151 "version": "1.0.2",
89 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 152 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
...@@ -94,6 +157,11 @@ ...@@ -94,6 +157,11 @@
94 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 157 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
95 "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 158 "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
96 }, 159 },
160 + "escape-string-regexp": {
161 + "version": "1.0.5",
162 + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
163 + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
164 + },
97 "etag": { 165 "etag": {
98 "version": "1.8.1", 166 "version": "1.8.1",
99 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 167 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
...@@ -136,6 +204,14 @@ ...@@ -136,6 +204,14 @@
136 "vary": "~1.1.2" 204 "vary": "~1.1.2"
137 } 205 }
138 }, 206 },
207 + "filelist": {
208 + "version": "1.0.1",
209 + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz",
210 + "integrity": "sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==",
211 + "requires": {
212 + "minimatch": "^3.0.4"
213 + }
214 + },
139 "finalhandler": { 215 "finalhandler": {
140 "version": "1.1.2", 216 "version": "1.1.2",
141 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 217 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
...@@ -160,6 +236,11 @@ ...@@ -160,6 +236,11 @@
160 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 236 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
161 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 237 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
162 }, 238 },
239 + "has-flag": {
240 + "version": "3.0.0",
241 + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
242 + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
243 + },
163 "http-errors": { 244 "http-errors": {
164 "version": "1.7.2", 245 "version": "1.7.2",
165 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 246 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
...@@ -190,6 +271,17 @@ ...@@ -190,6 +271,17 @@
190 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 271 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
191 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" 272 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
192 }, 273 },
274 + "jake": {
275 + "version": "10.8.2",
276 + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz",
277 + "integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==",
278 + "requires": {
279 + "async": "0.9.x",
280 + "chalk": "^2.4.2",
281 + "filelist": "^1.0.1",
282 + "minimatch": "^3.0.4"
283 + }
284 + },
193 "media-typer": { 285 "media-typer": {
194 "version": "0.3.0", 286 "version": "0.3.0",
195 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 287 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
...@@ -223,6 +315,14 @@ ...@@ -223,6 +315,14 @@
223 "mime-db": "1.44.0" 315 "mime-db": "1.44.0"
224 } 316 }
225 }, 317 },
318 + "minimatch": {
319 + "version": "3.0.4",
320 + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
321 + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
322 + "requires": {
323 + "brace-expansion": "^1.1.7"
324 + }
325 + },
226 "ms": { 326 "ms": {
227 "version": "2.0.0", 327 "version": "2.0.0",
228 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 328 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
...@@ -339,6 +439,14 @@ ...@@ -339,6 +439,14 @@
339 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 439 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
340 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 440 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
341 }, 441 },
442 + "supports-color": {
443 + "version": "5.5.0",
444 + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
445 + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
446 + "requires": {
447 + "has-flag": "^3.0.0"
448 + }
449 + },
342 "toidentifier": { 450 "toidentifier": {
343 "version": "1.0.0", 451 "version": "1.0.0",
344 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 452 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
......
1 +<input type="text" id="sample3_postcode" placeholder="우편번호">
2 +<input type="button" onclick="sample3_execDaumPostcode()" value="우편번호 찾기"><br>
3 +<input type="text" id="sample3_address" placeholder="주소"><br>
4 +<input type="text" id="sample3_detailAddress" placeholder="상세주소">
5 +<input type="text" id="sample3_extraAddress" placeholder="참고항목">
6 +
7 +<div id="wrap" style="display:none;border:1px solid;width:500px;height:300px;margin:5px 0;position:relative">
8 +<img src="//t1.daumcdn.net/postcode/resource/images/close.png" id="btnFoldWrap" style="cursor:pointer;position:absolute;right:0px;top:-1px;z-index:1" onclick="foldDaumPostcode()" alt="접기 버튼">
9 +</div>
10 +
11 +<script src="https://t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
12 +<script>
13 + // 우편번호 찾기 찾기 화면을 넣을 element
14 + var element_wrap = document.getElementById('wrap');
15 +
16 + function foldDaumPostcode() {
17 + // iframe을 넣은 element를 안보이게 한다.
18 + element_wrap.style.display = 'none';
19 + }
20 +
21 + function sample3_execDaumPostcode() {
22 + // 현재 scroll 위치를 저장해놓는다.
23 + var currentScroll = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
24 + new daum.Postcode({
25 + oncomplete: function(data) {
26 + // 검색결과 항목을 클릭했을때 실행할 코드를 작성하는 부분.
27 +
28 + // 각 주소의 노출 규칙에 따라 주소를 조합한다.
29 + // 내려오는 변수가 값이 없는 경우엔 공백('')값을 가지므로, 이를 참고하여 분기 한다.
30 + var addr = ''; // 주소 변수
31 + var extraAddr = ''; // 참고항목 변수
32 +
33 + //사용자가 선택한 주소 타입에 따라 해당 주소 값을 가져온다.
34 + if (data.userSelectedType === 'R') { // 사용자가 도로명 주소를 선택했을 경우
35 + addr = data.roadAddress;
36 + } else { // 사용자가 지번 주소를 선택했을 경우(J)
37 + addr = data.jibunAddress;
38 + }
39 +
40 + // 사용자가 선택한 주소가 도로명 타입일때 참고항목을 조합한다.
41 + if(data.userSelectedType === 'R'){
42 + // 법정동명이 있을 경우 추가한다. (법정리는 제외)
43 + // 법정동의 경우 마지막 문자가 "동/로/가"로 끝난다.
44 + if(data.bname !== '' && /[동|로|가]$/g.test(data.bname)){
45 + extraAddr += data.bname;
46 + }
47 + // 건물명이 있고, 공동주택일 경우 추가한다.
48 + if(data.buildingName !== '' && data.apartment === 'Y'){
49 + extraAddr += (extraAddr !== '' ? ', ' + data.buildingName : data.buildingName);
50 + }
51 + // 표시할 참고항목이 있을 경우, 괄호까지 추가한 최종 문자열을 만든다.
52 + if(extraAddr !== ''){
53 + extraAddr = ' (' + extraAddr + ')';
54 + }
55 + // 조합된 참고항목을 해당 필드에 넣는다.
56 + document.getElementById("sample3_extraAddress").value = extraAddr;
57 +
58 + } else {
59 + document.getElementById("sample3_extraAddress").value = '';
60 + }
61 +
62 + // 우편번호와 주소 정보를 해당 필드에 넣는다.
63 + document.getElementById('sample3_postcode').value = data.zonecode;
64 + document.getElementById("sample3_address").value = addr;
65 + // 커서를 상세주소 필드로 이동한다.
66 + document.getElementById("sample3_detailAddress").focus();
67 +
68 + // iframe을 넣은 element를 안보이게 한다.
69 + // (autoClose:false 기능을 이용한다면, 아래 코드를 제거해야 화면에서 사라지지 않는다.)
70 + element_wrap.style.display = 'none';
71 +
72 + // 우편번호 찾기 화면이 보이기 이전으로 scroll 위치를 되돌린다.
73 + document.body.scrollTop = currentScroll;
74 + },
75 + // 우편번호 찾기 화면 크기가 조정되었을때 실행할 코드를 작성하는 부분. iframe을 넣은 element의 높이값을 조정한다.
76 + onresize : function(size) {
77 + element_wrap.style.height = size.height+'px';
78 + },
79 + width : '100%',
80 + height : '100%'
81 + }).embed(element_wrap);
82 +
83 + // iframe을 넣은 element를 보이게 한다.
84 + element_wrap.style.display = 'block';
85 + }
86 +</script>
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require('express');
2 +const router = express.Router();
3 +
4 +router.get('/', function(req, res){
5 + res.render('index');
6 +});
7 +
8 +module.exports = router;
...\ No newline at end of file ...\ No newline at end of file