2014-05-09 200 views
2

我使用名为index.html的索引文件开发纯前端应用程序。每次我推送到heroku,我需要将其重命名为index.php,以告诉heroku使用php。是否有另一种方法来声明我想要的服务器类型?这样我就可以将我的文件保存为html文件?是否可以将index.html推送到heroku?

+0

你不能直接提供静态文件,但你可以通过简单的node.js应用程序来管理它。看到我的答案[这里](http://stackoverflow.com/questions/23564500/is-it-possible-to-push-a-index-html-to-heroku/23564786#23564786) –

回答

5

您也可以将一个空的composer.json放入您的项目中,以使Heroku将您的项目视为一个PHP项目。

index.php优于index.html来自Apache在Heroku上使用的默认指令DirectoryIndex;它与你的浏览器无关。要更改它,您可以将.htaccessDirectoryIndex index.html放入您的应用程序中。

如果你只是想要静态网站的原始性能,那么使用Nginx也可能是一个好主意。默认配置应该是合理的为您的目的,所以添加Procfileweb: vendor/bin/heroku-php-nginx您的项目连同一个空的composer.json(和index.php),并且你很好去。

有关更多详细信息,另请参阅https://devcenter.heroku.com/articles/php-supporthttps://devcenter.heroku.com/articles/custom-php-settings

2

你可以做到这一点简单node.js应用与ExpressJS;

让我们说你的项目文件夹中有一个名为public子文件夹,

var express = require('express'); 
var app = express(); 
app.use('/', express.static(__dirname + '/public')); 
var port = Number(process.env.PORT || 5000); 
app.listen(port, function() { 
    console.log('Your files will be served through this web server') 
}); 

保存此代码app.js,把你静态文件public文件夹下,并准备你的Procfile

最后的文件夹结构将会;

yourproject 
--public/ 
----your staticfiles 
--app.js 
--Procfile 

Procfile将;

web: node app.js 

并部署您的项目。当你请求你的静态文件时; .../index.html,index.html将在公共文件夹下提供

-1

添加一个名为index.php的空文件,这将被heroku使用,但index.html将由浏览器优先。