LightTable을 사용하여 nodejs 응용 프로그램을 만들고 있는데, <link href="">
태그의 상대 경로를 나타낼 때 CSS가 잘로드되는 것 같습니다. 그러나 node index.js
을 실행하면 서버가 시작되고 페이지가 잘로드되지만 콘솔 오류가 발생하고 CSS 404 파일을 지정한 경로에서 찾을 수 없다는 내용의 404 메시지가 표시됩니다. 나는 Heroku의 Foreman Start
을 사용해 보았지만 주사위는 사용하지 않았다. 여기에 HTML은 다음과 같습니다node.js 앱이 CSS가 내 IDE에서로드되지만 localhost에서는로드되지 않는 이유는 무엇입니까?
<!DOCTYPE html>
<html>
<head>
<title>
Home
</title>
<link href="../../styles/master.css" rel="stylesheet" type="text/css" />
</head>
...
여기 내 디렉토리 트리 구조입니다 :
.
├── Procfile
├── README.md
├── index.js
├── package.json
├── resources
│ └── images
│ └── tokyo.jpg
├── styles
│ └── master.css
└── views
├── get
│ ├── home.html
│ └── posts.html
└── post
└── new.html
편집 : 질문에 대한 답을 찾은 후, 아래의 내용과 관련이되었다. CSS와 백그라운드 이미지를 원하는대로로드하는 새로운 코드를 주석 처리했습니다.
내 라우팅 및 서버 코드입니다. Express를 사용하지 않고 있습니다.
// routes
var homeREGEX = new RegExp('^/?$');
var newREGEX = new RegExp('^/posts/new/?$');
var postsREGEX = new RegExp('^/posts/?$');
// var cssREGEX = new RegExp('^/styles/master.css/?$'); <--| static resources also
// var tokyoREGEX = new RegExp('^/resources/images/tokyo.jpg/?$'); <--| need routes.
// server
var server = http.createServer(function(request, response){
var pathname = url.parse(request.url).pathname;
if (homeREGEX.test(pathname)) {
renderHome(request, response);
} else if (newREGEX.test(pathname)) {
renderPostForm(request, response);
} else if (postsREGEX.test(pathname)) {
addNewPost(request, response);
// } else if (cssREGEX.test(pathname)) { <--| and they need to get
// sendCSS(request, response); <--| served individually as
// } else if (tokyoREGEX.test(pathname)) { <--| they are requested
// sendTokyo(request, response);
} else {
error404(request, response);
}
});
의 정확한 경로를 넣어 시도 할 수 있습니다 무엇 당신이 페이지를 찾을 때 당신은 당신의 브라우저에서보고가 작동하지 않습니다 URL? –
localhost : 3000,하지만 localhost : 3000/styles/master.css로 이동하면 404 오류가 발생합니다. – kurofune