[英].htaccess on heroku for angularjs app
我已经在heroku上使用lineman-angular模板部署了使用lineman构建的AngularJS应用。 启用了HTML5模式,我想在页面刷新时解决“找不到页面”问题。
按照这个答案,我可以看到可以将规则添加到.htaccess文件中。
因此,我创建了具有以下内容的文件:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png)
RewriteRule (.*) index.html [L]
</ifModule>
如果将.htaccess文件放在应用程序的根目录中,则我的应用程序将停止运行,并且会看到以下错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
我不知道需要在heroku cedar应用程序上创建.htaccess文件的位置。 有人可以帮我吗?
过了一会儿,我决定重温此问题,例如,配置服务器端以使其在启用了Html5模式的Heroku Angular.js应用程序上部署,该模式是使用Lineman.js构建的。
我检查了heroku-buildpack-lineman并发现了更新的信息,即可能不需要自定义构建包。 因此,我按照他们的说明配置了官方的Node.js buildpack:
$ heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs
$ heroku config:set NPM_CONFIG_PRODUCTION=false
然后包含一个Procfile:
web: npm run production
最后添加他们的生产脚本:
"scripts": {
"start": "lineman run",
"test": "lineman spec-ci",
"production": "lineman clean build && npm i express@3 && node -e \"var e = require('express'), a = e(); a.use(e.static('dist/')); a.listen(process.env.PORT)\""
},
但是,我还使用捕获所有路由中间件将快速重写代码包含在生产脚本中。
下面是修改后的生产脚本:
"production": "lineman clean build && npm i express@3 && node -e \"var e = require('express'), a = e(); a.use(e.static('dist/')); a.use(function(req, res) { res.sendfile('dist/index.html'); }); a.listen(process.env.PORT)\""
现在,部署在Heroku上的应用程序可以根据需要运行!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.