{"id":497,"date":"2022-01-28T13:29:20","date_gmt":"2022-01-28T04:29:20","guid":{"rendered":"https:\/\/blog.opendocs.co.kr\/?p=497"},"modified":"2022-01-28T15:46:03","modified_gmt":"2022-01-28T06:46:03","slug":"source-nodejs-%ec%99%b8%eb%b6%80%ec%97%b0%eb%8f%99-%ed%85%8c%ec%8a%a4%ed%8a%b8-%ec%84%9c%eb%b2%84","status":"publish","type":"post","link":"https:\/\/blog.opendocs.co.kr\/?p=497","title":{"rendered":"[Source | Nodejs] \uc678\ubd80\uc5f0\ub3d9 \ud14c\uc2a4\ud2b8 \uc11c\ubc84 &#8211; HTTP"},"content":{"rendered":"\n<p>\uc678\ubd80\uc5f0\ub3d9 \uac1c\ubc1c\uc2dc \uc784\uc2dc\ub85c \uc11c\ubc84\ub97c \uc2e4\ud589\ud574 \ub193\uace0 \ud14c\uc2a4\ud2b8 \ud558\uae30 \uc704\ud55c \ucf54\ub4dc\ub97c \uc815\ub9ac\ud55c\ub2e4.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">\uc791\uc131\uc77c : 2022-01-26\nnodeJs Ver : v16.13.1<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"400\" height=\"180\" src=\"https:\/\/blog.opendocs.co.kr\/wp-content\/uploads\/2021\/05\/nodejs_source.jpg\" alt=\"\" class=\"wp-image-305\" srcset=\"https:\/\/blog.opendocs.co.kr\/wp-content\/uploads\/2021\/05\/nodejs_source.jpg 400w, https:\/\/blog.opendocs.co.kr\/wp-content\/uploads\/2021\/05\/nodejs_source-300x135.jpg 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p> <strong>1> \ucf54\ub4dc\uc791\uc131 (server.js)<\/strong> <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n\/\/ For Execute Shell\n\/\/   node server.js\nconst http = require(&quot;http&quot;);\nconst fs = require('fs');\nconst port = 9090;\nconst name = &quot;OPENDOCS_TEST_SERVER&quot;;\n\nhttp.createServer((req, res) =&gt;{\n    let bodyStr = '';\n    req.on(&quot;data&quot;, chunk =&gt; {\n        bodyStr += chunk;\n    });\n    req.on(&quot;end&quot;, () =&gt; {\n        \/\/ Request\n        let transactionId = Date.now().toString();\n        console.log(`---------- Request (${name} : ${transactionId}) ----------`);\n        console.log(req.headers);\n        console.log(&quot;----------------------------------------&quot;);\n        console.log(bodyStr);\n\n        \/\/ Response        \n        let resStatus = 404;\n        let resHead = {&quot;Content-Type&quot;: &quot;application\/json&quot;, transactionId};\n        let resBody = {};\n        if(req.url == &quot;\/url_a&quot;) {\n            \/\/ - TODO\n            const fileName = 'url_a.json';\n            resStatus = 200;\n            resHead = {...resHead, &quot;additionalHead&quot;: &quot;url_a&quot;};\n            const jsonFile = fs.readFileSync(`.\/ServerTestCase\/${fileName}`, 'utf8');\n            resBody = JSON.parse(jsonFile);\n        } else if(req.url == &quot;\/url_b&quot;) {\n            \/\/ - TODO\n            const fileName = 'url_b.json';\n            resStatus = 200;\n            resHead = {...resHead, &quot;additionalHead&quot;: &quot;url_b&quot;};\n            const jsonFile = fs.readFileSync(`.\/ServerTestCase\/${fileName}`, 'utf8');\n            resBody = JSON.parse(jsonFile);\n        }\n        res.writeHead(resStatus, resHead);\n        res.end(JSON.stringify(resBody));\n\n        console.log(`---------- Response (${name} : ${transactionId}) ----------`);\n        console.log(resHead);\n        console.log(&quot;----------------------------------------&quot;);\n        console.log(resBody);\n        console.log(&quot;------------------------------------------------------------\/\/\\n\\n\\n&quot;);\n    });\n}).listen(port);\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>2> \uc751\ub2f5\uc0d8\ud50c \uc791\uc131<\/strong> : ServerTestCase \ud3f4\ub354 \uc544\ub798 \uc120\uc5b8\ud55c fileName \uacfc \uc77c\uce58\ud558\uac8c \uc0dd\uc131<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n\/\/ .\/ServerTestCase\/url_a.json\n{\n    &quot;TEST&quot;: &quot;TEST URL-A&quot;\n}\n\/\/ .\/ServerTestCase\/url_b.json\n{\n    &quot;TEST&quot;: &quot;TEST URL-B&quot;\n}\n<\/pre><\/div>\n\n\n<p>\ud30c\uc77c\uc744 \uc2e4\uc2dc\uac04\uc73c\ub85c \uc77d\uc5b4 \uc751\ub2f5\ud558\uae30 \ub54c\ubb38\uc5d0 \uc11c\ubc84 \uc7ac\uc2dc\uc791 \uc5c6\uc774 \uc751\ub2f5\uac12\uc744 \ubcc0\uacbd\ud558\uc5ec \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc678\ubd80\uc5f0\ub3d9 \uac1c\ubc1c\uc2dc \uc784\uc2dc\ub85c \uc11c\ubc84\ub97c \uc2e4\ud589\ud574 \ub193\uace0 \ud14c\uc2a4\ud2b8 \ud558\uae30 \uc704\ud55c \ucf54\ub4dc\ub97c \uc815\ub9ac\ud55c\ub2e4. \uc791\uc131\uc77c : 2022-01-26 nodeJs Ver : v16.13.1 1> \ucf54\ub4dc\uc791\uc131 (server.js) 2> \uc751\ub2f5\uc0d8\ud50c \uc791\uc131 : ServerTestCase \ud3f4\ub354 \uc544\ub798 \uc120\uc5b8\ud55c fileName \uacfc \uc77c\uce58\ud558\uac8c \uc0dd\uc131 \ud30c\uc77c\uc744 \uc2e4\uc2dc\uac04\uc73c\ub85c \uc77d\uc5b4 \uc751\ub2f5\ud558\uae30 \ub54c\ubb38\uc5d0 \uc11c\ubc84 \uc7ac\uc2dc\uc791 \uc5c6\uc774 \uc751\ub2f5\uac12\uc744 \ubcc0\uacbd\ud558\uc5ec \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\ub2e4.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[146,147,148,144,149,145],"_links":{"self":[{"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/497"}],"collection":[{"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=497"}],"version-history":[{"count":4,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.opendocs.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}