3

I am using lite-server to help with the development of ng2 apps (to which I am new). It refreshes my index.html in the browser whenever changes are made in the project.

But what in the case where I'm dealing with index.php? Before I'd serve it through my LAMP stack.

How can I combine the ease of use of lite-server when developing ng2 apps with the need for php compilation? Is there some configuration that I can adjust in lite-server for it to launch a different URL for instance (that points to apache instead of localhost:3000)? I checked the readme, but it doesn't mention something like this, nor can I find something with a google search.

Willem van Gerven
  • 1,407
  • 1
  • 17
  • 24

2 Answers2

1

updated answer

I updated the answer, because it is not working as expected with the proxy-middleware. I tried the connect-modrewrite instead, which is working as expected.

First, you need to install the middleware like this:

npm install connect-modrewrite --save-dev

Then you can add the rule like this in your browserSync config:

middleware : [
    require('connect-modrewrite')([
        `^/$ ${BACKEND_HOST}${BACKEND_URI}index.php [P]`
    ])
]

old answer

You can add the http-proxy-middleware. With it, it should be possible to rewrite the index to your apache index.

You can find an example of adding a middleware to lite-server here: https://github.com/johnpapa/lite-server#custom-configuration

Dinistro
  • 5,701
  • 1
  • 30
  • 38
  • I just now looked at the documentation for browsersync (https://www.browsersync.io/docs/options/#option-proxy). As an alternative to your advise, couldn't I just configure it with a proxy to the apache localhost? (I'm not at home now, otherwise I had tried it.) – Willem van Gerven Apr 28 '16 at 09:08
  • 1
    @WillemvanGerven As far as I know, this will redirect all your request to the apache, so you will not be able to load something from `browserSync`. – Dinistro Apr 28 '16 at 09:15
  • 1
    @WillemvanGerven I just updated the answer. The problem with the proxy-middleqare is, that it can only apply to a directory and not only a file, or atleast not only the index call (`/`). I hope this helps you – Dinistro Apr 28 '16 at 11:03
  • 1
    Hi Dinistro, thanks a bunch for editing, this works like a charm now! – Willem van Gerven Apr 28 '16 at 19:17
0

I don't know if can help, but I added too:

files: [
    "*","*.*","**"
]

because browserSync was missing whatching php files.

So, in general, my bs-config.js file looks like:

module.exports = {
files: [
    "*","*.*","**"
],
server: {
    middleware: {
        1: require('connect-modrewrite')(['^/$ http://localhost/testing/angular2/index.php [P]'])
    }
}

};

where http://localhost/ is my wamp server and testing/angular2/ my folder location, the same in which launch the lite-server

Ade
  • 33
  • 4