lite-server
lite-server copied to clipboard
How to properly configure multiple routes in lite-server
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.html
loading foo.js
script as well as accesslocalhost:8000/bar
and get bar/index.html
loading 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.
I am also looking for a solution to this problem. Did you have any luck finding a way to do it?
@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
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.
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.
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