在heroku node js应用程序中提供文件

时间:2014-05-21 12:28:49

标签: javascript node.js heroku socket.io

我是节点新手。我已经在Heroku中创建并成功测试了节点应用程序。我的文件夹结构是这样的。

app.js ( the server side socket.iofile).
index.html (publicly available file).

当我通过

Heroku
中的网址访问应用时。 如果我访问
app.js
appname.herokuapp.com/app.js
文件,我可以访问该文件。有什么方法可以阻止访问此服务器文件吗?

此致 Harilal

2 个答案:

答案 0 :(得分:0)

好吧,你可能正在使用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
});

答案 1 :(得分:0)

实际上我没有使用" express"。 我的代码是这样的 http://pastebin.com/7BcZZsMk

我的文件夹结构如下:

app
----css
--------style.css
----images
--------cup.png
--------tree.png
----app.js
----index.html
相关问题