lite-server icon indicating copy to clipboard operation
lite-server copied to clipboard

How to properly configure multiple routes in lite-server

Open bernardopacheco opened this issue 8 years ago • 5 comments

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.

bernardopacheco avatar Aug 03 '16 03:08 bernardopacheco

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

RichardGrundy avatar Aug 19 '16 12:08 RichardGrundy

@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

bernardopacheco avatar Aug 19 '16 14:08 bernardopacheco

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.

maciej-gurban avatar Sep 01 '16 10:09 maciej-gurban

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.

RichardGrundy avatar Sep 01 '16 10:09 RichardGrundy

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

maciej-gurban avatar Sep 01 '16 11:09 maciej-gurban