Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sejong25
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Tear of Sejong
sejong25
Commits
7ba7c905
Commit
7ba7c905
authored
Jun 25, 2019
by
14이종민
🥝
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodejs server test
parent
7e015638
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
server.js
server.js
+38
-0
No files found.
server.js
0 → 100644
View file @
7ba7c905
var
http
=
require
(
"
http
"
);
var
fs
=
require
(
"
fs
"
);
var
url
=
require
(
"
url
"
);
http
.
createServer
(
function
(
request
,
response
)
{
// URL 뒤에 있는 디렉토리/파일이름 파싱
var
pathname
=
url
.
parse
(
request
.
url
).
pathname
;
console
.
log
(
"
Request for
"
+
pathname
+
"
received.
"
);
// 파일 이름이 비어있다면 index.html 로 설정
if
(
pathname
==
"
/
"
){
pathname
=
"
/index.html
"
;
}
// 파일을 읽기
fs
.
readFile
(
pathname
.
substr
(
1
),
function
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
err
);
// 페이지를 찾을 수 없음
// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
response
.
writeHead
(
404
,
{
'
Content-Type
'
:
'
text/html
'
});
}
else
{
// 페이지를 찾음
// HTTP Status: 200 : OK
// Content Type: text/plain
response
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
text/html
'
});
// 파일을 읽어와서 responseBody 에 작성
response
.
write
(
data
.
toString
());
}
// responseBody 전송
response
.
end
();
});
}).
listen
(
8081
);
console
.
log
(
'
Server running at http://127.0.0.1:8081/
'
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment