我試圖在Express和Node.js中構建應用程序。我的服務器文件包含在app
文件夾中,並且前端的內容位於公用文件夾中。帶有相對路徑的本地文件無法在NodeJS Express應用程序中加載
我的文件結構是這樣的:
my_project
|- app
| |-(server stuff)
| |- ....
|- public
| |- modules
| | |- core
| | | |- index.html
| | | |- style
| | | | |style.css
| | | | |sidebar.css
| | | |- img
| | | | |- faceicon.png
| | | | |- main.png
| | | |- js
| | | | |main.js
| | | | |sidebar.js
| | |- articles
| | | |- ....
的問題是,在我的index.html
文件,當我引用類似
<link href="style/style.css" rel="stylesheet">
或文件在我style.css
像
background: url(../img/faceicon.jpg) no-repeat bottom center scroll;
預期結果t不顯示在屏幕上,我得到控制檯消息,如
GET http://localhost:3000/img/faceicon.png 500 (Internal Server Error)
如何解決這個問題?
好像你沒有'css'文件夾。 – 2015-02-10 12:00:45
@AleksandrM對不起,修正了 – CodyBugstein 2015-02-10 12:24:33
圖片路徑應該是'http:// localhost:3000/modules/core/img/faceicon.png' – Sami 2015-02-10 12:40:59