Javascript 在heroku node js应用程序中提供文件
我不熟悉node。我已经在Heroku中创建并成功测试了node应用程序。我的文件夹结构是这样的 app.js ( the server side socket.iofile). app.js(服务器端socket.iofile)。 index.html(公开可用的文件)。 当我通过Heroku的URL访问应用程序时。 Heroku 如果我访问appname.herokuapp.com/app.js这样的app.js文件,我就可以访问该文件。是否有任何方法阻止访问此服务器文件 app.js 问候Javascript 在heroku node js应用程序中提供文件,javascript,node.js,heroku,socket.io,Javascript,Node.js,Heroku,Socket.io,我不熟悉node。我已经在Heroku中创建并成功测试了node应用程序。我的文件夹结构是这样的 app.js ( the server side socket.iofile). app.js(服务器端socket.iofile)。 index.html(公开可用的文件)。 当我通过Heroku的URL访问应用程序时。 Heroku 如果我访问appname.herokuapp.com/app.js这样的app.js文件,我就可以访问该文件。是否有任何方法阻止访问此服务器文件 app.js 问候
Harilal好吧,您可能正在使用express.static(),因为它可以访问目录中的任何静态文件。无论如何,您可以为app.js创建路由:
var app=express();
app.use(app.router); //this will make sure that node.js will check for a route before checking for app.js file and displaying it.
app.use(express.static(__dirname+'/directoryPath'));
//now set the route for app.js
app.get('/app.js',function(req,res){
//what-ever you want should happen when u go to appname.herokuapp.com/app.js
});
其实我不是在用“快车”。
我的代码是这样的
我的文件夹结构如下所示:
app
----css
--------style.css
----images
--------cup.png
--------tree.png
----app.js
----index.html
关于您的实际案例,这方面的信息太少了:您的http服务器构建是什么样的(express/http?),静态文件的中间件是如何加载的,您真正的目录结构是什么。。。?
var app=express();
app.use(app.router); //this will make sure that node.js will check for a route before checking for app.js file and displaying it.
app.use(express.static(__dirname+'/directoryPath'));
//now set the route for app.js
app.get('/app.js',function(req,res){
//what-ever you want should happen when u go to appname.herokuapp.com/app.js
});
app
----css
--------style.css
----images
--------cup.png
--------tree.png
----app.js
----index.html