정적인 파일 서비스
정적인 파일 : 이미지파일, 자바스크립트, css파일 등을 웹브라우저로 다운로드 시킨 경우
app.use(express.static('public'))
// css ( style옵션 ) 추가함 (사이즈 변경) .
,
<img src="/images/hello.jpg" style="width:400px; display:block; margin-top:10px">`,
==> 추가된 코드 위치.
// 1. 홈페이지 구현.
app.get('/', (request, response) => {
var title = 'Welcome';
var description = 'Hello, Node.js';
var list = template.list(request.list);
var html = template.HTML(title, list,
`<h2>${title}</h2>${description},
<img src="/images/hello.jpg" style="width:400px; display:block; margin-top:10px">`,
`<a href="/create">create</a>`
);
response.send(html);
})
7. Totall
:'public' directory 안에서 static 파일을 찾겠다!! 라고 직접 지정한다.
app.use(express.static('public'))
이 코드는..
'public' directory 안의 파일 or directory 만 url을 통해 접근가능하고, 여기만 접근허용이므로 훨씬 안전해짐.