생활코딩 Node.js-11. App제작-동적인 웹페이지 만들기 main.js 실행되는 코드
2022. 7. 21. 20:29ㆍCLUG(중앙대학교 sw 과동아리)/server
728x90
var http = require('http');
var fs = require('fs');
var url = require('url');
var app = http.createServer(function(request,response){
var _url = request.url;
var queryData = new URL('http://localhost:3000' + _url).searchParams;
var title = queryData.get('id');
console.log(queryData.get('id'));
if(_url == '/'){
url = '/index.html';
}
if(_url == '/favicon.ico'){
response.writeHead(404);
response.end();
return;
}
response.writeHead(200);
//웹페이지에 뭔가 띄우기
var template = `<!doctype html>
<html>
<head>
<title>WEB1 - ${title} </title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="index.html">WEB</a></h1>
<ol>
<li><a href="/?id=HTML">HTML</a></li>
<li><a href="/?id=CSS">CSS</a></li>
<li><a href="/?id=JavaScript">JavaScript</a></li>
</ol>
<h2>${title}</h2>
<p><a href="https://www.w3.org/TR/html5/" target="_blank" title="html5 speicification">Hypertext Markup Language (HTML)</a> is the standard markup language for <strong>creating <u>web</u> pages</strong> and web applications.Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.
<img src="coding.jpg" width="100%">
</p><p style="margin-top:45px;">HTML elements are the building blocks of HTML pages. With HTML constructs, images and other objects, such as interactive forms, may be embedded into the rendered page. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. HTML elements are delineated by tags, written using angle brackets.
</p>
</body>
</html>
`;
//console.log(__dirname + url);
response.end(template);
});
app.listen(3000);
'CLUG(중앙대학교 sw 과동아리) > server' 카테고리의 다른 글
[npm] uglifyjs_기계가 코드를 처리하는데 필요한 필수적인 코드만 남겨준다 (0) | 2022.07.26 |
---|---|
생활코딩 Node.js-13 App제작-파일을 이용해 본문 구현(해결못함 ㅠ) (0) | 2022.07.21 |
Node.js - url의 이해 (0) | 2022.07.21 |
[nodejs] atom cmd창에서 실행하기 (0) | 2022.07.20 |
node.js 시작 (0) | 2022.07.19 |