johnpapa / lite-server

Lightweight node server
MIT License
2.31k stars 267 forks source link

How to properly configure multiple routes in lite-server #93

Open bernardopacheco opened 8 years ago

bernardopacheco commented 8 years ago

I'm using the lite-server to develop an Angular application. I have the following project structure, very simple:

build/
    foo/
        index.html (references foo.js script)
    bar/
        index.html (references bar.js script)
foo.js
bar.js
bsconfig.json

What a I want to do is to access localhost:8000/foo and get foo/index.htmlloading foo.js script as well as accesslocalhost:8000/bar and get bar/index.htmlloading bar.js.

I've read the Browsersync options documentation and tried configuring the bs-config.json file using routes but I couldn't get it working.

RichardGrundy commented 8 years ago

I am also looking for a solution to this problem. Did you have any luck finding a way to do it?

bernardopacheco commented 8 years ago

@RichardGrundy Sadly I haven't found out a solution for it yet.

I've also posted a question in StackOverflow about it to see if someone can help.

http://stackoverflow.com/questions/38733493/how-to-properly-configure-multiple-routes-in-lite-server

maciej-gurban commented 8 years ago

Pardon my ignorance, but why do you want to solve it on the browsersync/lite-server side? This would require you configure server to mirror that routing. Looks like all you need to do is to create two routes in your application, each pointing to a different template file.

RichardGrundy commented 8 years ago

Its purely for testing, each application is independent and will run on different servers when in production. Just during build and test each references a central core library of components so for speed and convenience I am not running 3 web servers but one with one core set of libraries and 3 angular 2 apps.

maciej-gurban commented 8 years ago

I see. Browsersync accepts custom middleware functions (basically request/response interceptors). You could use these to route your traffic to different locations.

Docs: https://www.browsersync.io/docs/options#option-middleware

Edit: This scotch.io article has some more complete examples on how to use custom middlewares: https://scotch.io/bar-talk/a-fast-and-convenient-development-server-with-lite-server