Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提供express静态文件时未找到_Javascript_Node.js_Express - Fatal编程技术网

Javascript 提供express静态文件时未找到

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

我想访问我的web应用程序的一个页面。我使用expressJs创建了服务器,并使用
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文件,它工作得更好!