diff options
author | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:48:24 +0100 |
---|---|---|
committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:48:24 +0100 |
commit | ee778d6eea54935fd05022e0ba8c49456003381a (patch) | |
tree | 151a4cef804d8823cc8fc753b8edc693b7078241 /files/ko/learn/server-side | |
parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
download | translated-content-ee778d6eea54935fd05022e0ba8c49456003381a.tar.gz translated-content-ee778d6eea54935fd05022e0ba8c49456003381a.tar.bz2 translated-content-ee778d6eea54935fd05022e0ba8c49456003381a.zip |
unslug ko: move
Diffstat (limited to 'files/ko/learn/server-side')
-rw-r--r-- | files/ko/learn/server-side/express_nodejs/development_environment/index.html (renamed from files/ko/learn/server-side/express_nodejs/개발_환경/index.html) | 0 | ||||
-rw-r--r-- | files/ko/learn/server-side/express_nodejs/skeleton_website/index.html (renamed from files/ko/learn/server-side/express_nodejs/스켈레톤_웹사이트/index.html) | 0 | ||||
-rw-r--r-- | files/ko/learn/server-side/node_server_without_framework/index.html | 74 |
3 files changed, 74 insertions, 0 deletions
diff --git a/files/ko/learn/server-side/express_nodejs/개발_환경/index.html b/files/ko/learn/server-side/express_nodejs/development_environment/index.html index f3ab1846f6..f3ab1846f6 100644 --- a/files/ko/learn/server-side/express_nodejs/개발_환경/index.html +++ b/files/ko/learn/server-side/express_nodejs/development_environment/index.html diff --git a/files/ko/learn/server-side/express_nodejs/스켈레톤_웹사이트/index.html b/files/ko/learn/server-side/express_nodejs/skeleton_website/index.html index ca72e39124..ca72e39124 100644 --- a/files/ko/learn/server-side/express_nodejs/스켈레톤_웹사이트/index.html +++ b/files/ko/learn/server-side/express_nodejs/skeleton_website/index.html diff --git a/files/ko/learn/server-side/node_server_without_framework/index.html b/files/ko/learn/server-side/node_server_without_framework/index.html new file mode 100644 index 0000000000..1050f6aafd --- /dev/null +++ b/files/ko/learn/server-side/node_server_without_framework/index.html @@ -0,0 +1,74 @@ +--- +title: Node server without framework +slug: Node_server_without_framework +translation_of: Learn/Server-side/Node_server_without_framework +--- +<h2 id="소개">소개</h2> + +<p>물론 <a href="https://nodejs.org/en/">Node</a> 는 서버를 만들고 실행하는데 도움을 주는 많은 프레임워크가 있습니다, 예를 들면:</p> + +<ul> + <li><a href="http://expressjs.com/">Express</a>: 가장 많이 사용하는 프레임워크</li> + <li><a href="https://www.totaljs.com/">Total</a>: 올인원 통합 프레임워크로, 다른 프레임워크나 모듈에 의존성이 없습니다.</li> +</ul> + +<p>하지만, 모든 것에 꼭 맞는 사이즈가 없듯이, 개발자들은 어떤 다른 의존성 없이 스스로 서버를 만들어야 할 때가 있습니다.</p> + +<h2 id="예제">예제</h2> + +<p>다음은 짧고 간단한 정적 파일 nodejs 서버입니다.</p> + +<pre>var http = require('http'); +var fs = require('fs'); +var path = require('path'); + +http.createServer(function (request, response) { + console.log('request ', request.url); + + var filePath = '.' + request.url; + if (filePath == './') + filePath = './index.html'; + + var extname = String(path.extname(filePath)).toLowerCase(); + var contentType = 'text/html'; + var mimeTypes = { + '.html': 'text/html', + '.js': 'text/javascript', + '.css': 'text/css', + '.json': 'application/json', + '.png': 'image/png', + '.jpg': 'image/jpg', + '.gif': 'image/gif', + '.wav': 'audio/wav', + '.mp4': 'video/mp4', + '.woff': 'application/font-woff', + '.ttf': 'application/font-ttf', + '.eot': 'application/vnd.ms-fontobject', + '.otf': 'application/font-otf', + '.svg': 'application/image/svg+xml' + }; + + contentType = mimeTypes[extname] || 'application/octet-stream'; + + fs.readFile(filePath, function(error, content) { + if (error) { + if(error.code == 'ENOENT'){ + fs.readFile('./404.html', function(error, content) { + response.writeHead(200, { 'Content-Type': contentType }); + response.end(content, 'utf-8'); + }); + } + else { + response.writeHead(500); + response.end('Sorry, check with the site admin for error: '+error.code+' ..\n'); + response.end(); + } + } + else { + response.writeHead(200, { 'Content-Type': contentType }); + response.end(content, 'utf-8'); + } + }); + +}).listen(8125); +console.log('Server running at http://127.0.0.1:8125/');</pre> |