使用 lite-server 进行 ng2 应用程序开发,如何使用 php?
Using lite-server for ng2 app development, how to work with php?
我正在使用 lite-server 来帮助开发 ng2 应用程序(我是新手)。每当在项目中进行更改时,它都会在浏览器中刷新我的 index.html。
但是如果我正在处理 index.php 呢?在我通过我的 LAMP 堆栈提供它之前。
在开发 ng2 应用程序时,如何将 lite-server 的易用性与 php 编译的需要结合起来?是否有一些我可以在 lite-server 中调整的配置,以启动不同的 URL(例如指向 apache 而不是 localhost:3000)?我查看了自述文件,但它没有提到类似的内容,我也无法通过 google 搜索找到内容。
更新答案
我更新了答案,因为它没有像预期的那样与代理中间件一起工作。我尝试了 connect-modrewrite,它按预期工作。
首先,你需要像这样安装中间件:
npm install connect-modrewrite --save-dev
然后您可以在您的 browserSync 配置中添加这样的规则:
middleware : [
require('connect-modrewrite')([
`^/$ ${BACKEND_HOST}${BACKEND_URI}index.php [P]`
])
]
旧答案
您可以添加http-proxy-middleware。有了它,应该可以将索引重写为您的 apache 索引。
您可以在此处找到向 lite-server 添加中间件的示例:https://github.com/johnpapa/lite-server#custom-configuration
不知道能不能帮上忙,我也补充了:
files: [
"*","*.*","**"
]
因为 browserSync 缺少 php 个文件。
所以,一般来说,我的 bs-config.js 文件看起来像:
module.exports = {
files: [
"*","*.*","**"
],
server: {
middleware: {
1: require('connect-modrewrite')(['^/$ http://localhost/testing/angular2/index.php [P]'])
}
}
};
其中 http://localhost/ 是我的 wamp 服务器,testing/angular2/ 我的文件夹位置,与启动 lite-server 的位置相同
我正在使用 lite-server 来帮助开发 ng2 应用程序(我是新手)。每当在项目中进行更改时,它都会在浏览器中刷新我的 index.html。
但是如果我正在处理 index.php 呢?在我通过我的 LAMP 堆栈提供它之前。
在开发 ng2 应用程序时,如何将 lite-server 的易用性与 php 编译的需要结合起来?是否有一些我可以在 lite-server 中调整的配置,以启动不同的 URL(例如指向 apache 而不是 localhost:3000)?我查看了自述文件,但它没有提到类似的内容,我也无法通过 google 搜索找到内容。
更新答案
我更新了答案,因为它没有像预期的那样与代理中间件一起工作。我尝试了 connect-modrewrite,它按预期工作。
首先,你需要像这样安装中间件:
npm install connect-modrewrite --save-dev
然后您可以在您的 browserSync 配置中添加这样的规则:
middleware : [
require('connect-modrewrite')([
`^/$ ${BACKEND_HOST}${BACKEND_URI}index.php [P]`
])
]
旧答案
您可以添加http-proxy-middleware。有了它,应该可以将索引重写为您的 apache 索引。
您可以在此处找到向 lite-server 添加中间件的示例:https://github.com/johnpapa/lite-server#custom-configuration
不知道能不能帮上忙,我也补充了:
files: [
"*","*.*","**"
]
因为 browserSync 缺少 php 个文件。
所以,一般来说,我的 bs-config.js 文件看起来像:
module.exports = {
files: [
"*","*.*","**"
],
server: {
middleware: {
1: require('connect-modrewrite')(['^/$ http://localhost/testing/angular2/index.php [P]'])
}
}
};
其中 http://localhost/ 是我的 wamp 服务器,testing/angular2/ 我的文件夹位置,与启动 lite-server 的位置相同