是否可以将index.html推送到heroku?
I develop a pure front-end app with an index-file called index.html. Everytime I push to heroku, i need to rename it index.php, in order to tell heroku to use php. Is there another way to declare what type of server I want? So that I get to keep my file as an html-file?
我开发了一个带有索引文件index.html的纯前端应用程序。 每次我推送到heroku,我需要将其重命名为index.php,以告诉heroku使用php。 有没有其他方法来声明我想要什么类型的服务器? 这样我就可以将我的文件保存为html文件了吗? p> div>
You can also just drop an empty composer.json
into your project to make Heroku treat your project as a PHP project.
The preference of index.php
over index.html
comes from the default DirectoryIndex
directive that Apache uses on Heroku; it has nothing to do with your browser. To change it, you could drop a .htaccess
with DirectoryIndex index.html
into your application.
If you just want raw performance for your static site, it's also probably a good idea to use Nginx. The default configuration should be reasonable for your purposes so add a Procfile
with web: vendor/bin/heroku-php-nginx
to your project along with an empty composer.json
(and no index.php
) and you're good to go.
Also see https://devcenter.heroku.com/articles/php-support and https://devcenter.heroku.com/articles/custom-php-settings for more details.
You can do that simple node.js app with ExpressJS;
Let say your project folder has a sub folder called 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')
});
Save this code in app.js, put your static files under public
folder, and prepare your Procfile
Final folder structure will be;
yourproject
--public/
----your staticfiles
--app.js
--Procfile
Procfile
will be;
web: node app.js
And deploy your project. When you request your static files like; .../index.html
, index.html
will be served under public folder
Add a empty file called index.php, this will be used by heroku, though, index.html will be prioritised by browsers.