Javascript 提供express静态文件时未找到
我想访问我的web应用程序的一个页面。我使用expressJs创建了服务器,并使用Javascript 提供express静态文件时未找到,javascript,node.js,express,Javascript,Node.js,Express,我想访问我的web应用程序的一个页面。我使用expressJs创建了服务器,并使用app.use(express.static())为路由提供服务 这是我的树: client |___Consultation | |___Parametrage | | | | | |___parametrage.html | | |___parametrage.css | | |___parametrage.j
app.use(express.static())
为路由提供服务
这是我的树:
client
|___Consultation
| |___Parametrage
| | |
| | |___parametrage.html
| | |___parametrage.css
| | |___parametrage.js
| |
| |___consultation.html
|
|___index.html
app.js
在app.js
文件中,我有以下内容:
app.use('/MPS', express.static(__dirname + '/client'));
app.use("/Consultation", express.static(__dirname + '/client/Consultation'));
app.use("/Parametrage/", express.static(__dirname + '/client/Consultation/Parametrage/'));
行app.use('/MPS',express.static(uu dirname+'/client')代码>工作正常:当我进入http://localhost:8080/MPS
将显示页面index.html
但是当我进入http://localhost:8080/Consultation
或http://localhost:8080/Parametrage
,不显示consultation.html
或parametrace.html
我有一个错误:无法获取/咨询/
我不知道如何修复它,因此非常感谢您的帮助。如果您不在url中指定特定的html
-页面,默认值为index.html
。由于咨询/参数子文件夹中没有索引文件,您会看到上面的错误
如果你要求的话
http://localhost:8080/Consultation/consultation.html
它应该很好用。或者,您也可以将consultation.html
重命名为index.html
,并使用http://localhost:8080/Consultation
您的位置/client
有文件index.html
尝试将同一文件放在其他位置。
基本上重命名consultation.html->index.html
和parametrage.html->index.html
对于其他路由,使用以下语法
app.use('/admin', function (req, res, next) {
// GET 'http://www.example.com/admin/new'
console.dir(req.originalUrl)
// '/admin/new' console.dir(req.baseUrl)
// '/admin' console.dir(req.path)
// '/new' next()
});
或
定位索引文件
http://localhost:8080/Consultation/consultation.html
谢谢!我用索引重命名了我的html文件,它工作得更好!