admin管理员组文章数量:1296844
I have a directory with some images in it that I want to make viewable in a browser.
This directory lives on my server at /public/images
Inside /public I also have other directories that I do not want to make public, hence making the entire /public directory viewable is not the solution.
How can I using the connect directory middleware make just my /public/images browsable?
Using the solution described here makes everything in /public viewable and trying the following doesn't work :
app.use(exp.static(__dirname + '/public'));
app.use(exp.static(__dirname + '/public/images'));
app.use(exp.directory(__dirname + '/public/images'));
I have a directory with some images in it that I want to make viewable in a browser.
This directory lives on my server at /public/images
Inside /public I also have other directories that I do not want to make public, hence making the entire /public directory viewable is not the solution.
How can I using the connect directory middleware make just my /public/images browsable?
Using the solution described here makes everything in /public viewable and trying the following doesn't work :
app.use(exp.static(__dirname + '/public'));
app.use(exp.static(__dirname + '/public/images'));
app.use(exp.directory(__dirname + '/public/images'));
Share
Improve this question
edited May 11, 2023 at 16:20
Rohad Bokhar
969 bronze badges
asked Jul 16, 2012 at 17:44
braitschbraitsch
15.3k5 gold badges45 silver badges38 bronze badges
2 Answers
Reset to default 9You have to mount your routes to a special path, like
app.use('/', exp.static(__dirname + '/public'));
app.use('/images', exp.static(__dirname + '/public/images'));
app.use('/images',exp.directory(__dirname + '/public/images'));
This way you can access the content of /public with the url / and the content of /public/image with the url /images
Express 4:
npm install serve-index
--
var serveIndex = require('serve-index');
app.use('/images', express.static(__dirname + '/public/images'), serveIndex(__dirname + '/public/images'));
本文标签: javascriptMaking a specific directory browsable in ExpressjsStack Overflow
版权声明:本文标题:javascript - Making a specific directory browsable in Express.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741641912a2389966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论