728x90
const http = require('http');
const hostname = '127.0.0.1';
const port = 1080;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
console.log(req);
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
console.log(req);
์์ฒญ ๊ฐ์ฒด
ํค๋๋ ๋ฉํ๋ฐ์ดํฐ ์ฆ, ์์ฒญ ๋ฐ ์๋ต์ ์ถ๊ฐ๋ ๋ฉํ ์ ๋ณด์ด๋ค. ์ ์บก์ฒ์ ๊ฐ์ด req ๊ฐ์ฒด๋ฅผ ์ฝ์ ๋ก๊ทธ์ ์ฐ์ผ๋ฉด ์๋ฅผ ๋ค์ด ์๋ต ๋ฐ์ดํฐ ์บ์ ๋ฐฉ๋ฒ, ์์ฒญ์ ์ฌ์ฉ๋๋ ๋ธ๋ผ์ฐ์ , ์๋ต(accept)์ ํ์ผ๋ก๋ html, xml ์๋ต์ ์ถ์ํด ๋์ญํญ์ ์๋ผ๋ ์ํธํ ์๋ต ๋ฑ์ ํค๋๊ฐ ๋์จ๋ค. |
์ด๋ ๋ฏ ํ ์์ฒญ์์ ์๋ง์ ๋ฐ์ดํฐ๋ฅผ ์ป์ ์ ์๋ค.
๊ทธ ์ค...
์ค์ํ ํ๋(1) : url
console.log(req.url, req.method, req.headers);
console.log(req.url, req.method, req.headers);
/ GET ํค๋ ๊ทธ์์ฒด ์ฐํ๋์ด
// ์ฐธ๊ณ ๋ก URL์ ๋ธ๋ผ์ฐ์ ์ ์
๋ ฅํ๋ ๊ฒฝ์ฐ GET ๋ฉ์๋๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉํ๋ค.
url์ ํธ์คํธ ๋ค์์ ๋ถ๋ ๋ชจ๋ ์ฃผ์์ธ๋ฐ, http://localhost:3001/
์ด ๊ฒฝ์ฐ localhost ์ธ์ ์๋ฌด ๊ฒ๋ ์๊ธฐ ๋๋ฌธ์ / ๋ง ๋์จ ๊ฒ์ด๋ค.
์ฃผ์์ฐฝ์ / ๋ค์ test๋ฅผ ์ถ๊ฐํ๊ณ ๋ค์ ํ์ธํด๋ณด๋ฉด..
728x90