Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option to set the base-href #595

Closed
zshlomyz opened this issue Dec 30, 2019 · 13 comments
Closed

An option to set the base-href #595

zshlomyz opened this issue Dec 30, 2019 · 13 comments

Comments

@zshlomyz
Copy link

zshlomyz commented Dec 30, 2019

Hi,
I want to configure the http-server to listen to a URL that contain a virtual, like:
http://localhost:<port>/<virtual-path>.
I can't find a way to doing that using the available options.
Is anyone know a way to do that?
Thanks

@thornjad
Copy link
Member

I don't think I'm understanding what you'd like to do. Are you wanting to serve files in a way where you would go to http://localhost:/. in the browser? Or are you wanting to serve a file called .?

@zshlomyz
Copy link
Author

zshlomyz commented Jan 1, 2020

Hi @thornjad , There was a problem with my question.
I fix that. I'll be happy if you can have another look to try help me.
Thanks

@thornjad
Copy link
Member

thornjad commented Jan 1, 2020

What do you mean by virtual path? Are you wanting to be able to request something like /foo/bar even when the foo/bar file doesn't exist?

@zshlomyz
Copy link
Author

zshlomyz commented Jan 2, 2020

What I want is to configure the http-server to respond to http://localhost:5000/foo the same as if the request was http://localhost:5000.
For example:

  • GET http://localhost:5000/foo - the response will be the index.html file from the static files folder.
  • GET http://localhost:5000/foo/bar.css - the respond will be the bar.css file from the static files folder.

@thornjad
Copy link
Member

thornjad commented Jan 4, 2020 via email

@zshlomyz
Copy link
Author

zshlomyz commented Jan 9, 2020

No. There is any rewrite option that can help me?

@peterjhart
Copy link

@zshlomyz See #542, #318

@culmat
Copy link

culmat commented Mar 14, 2020

this seems to be a duplicate of #294

@github-actions
Copy link

This issue has been inactive for 180 days

@github-actions github-actions bot added the stale label Aug 19, 2021
@thornjad
Copy link
Member

I'm considering this a duplicate of #139, please reopen if I've misunderstood the request

@sneakers-the-rat
Copy link

I think this is a different thing than #139, as I just came across it -- for example jekyll lets you set a baseurl configuration option for pages that are built and served from subdirectories of a website.

For example if one had their blog at https://mainurl.com/subpage/blog then all the local links within the page will be, eg <script src='/subpage/blog/asset.js'/> even though you may be building into a temporary _site directory.

So currently, one could go into the _site directory and do http-server and get the html index.html file served correctly, but since all the local links to eg. js and css are /subpage/blog/... then you get 404's for all of them.

Jekyll's server rewrites the url so that going to localhost:port/subpage/blog serves all the content from the _site root (so you don't need to build into artificial subdirectories)

webpack does something similar, so this would be very helpful for independent testing of bundled sites like that <3

@AnderssonPeter
Copy link

AnderssonPeter commented May 25, 2022

I'm guessing what they need is the ability to add a virtual folder that doesn't exist on disk.

So lets say I start http-server normally then requests to http://localhost/text.txt would go to ./text.txt but if I add this parameter with the value /content/ then I must request http://localhost/content/text.txt to get the same file, if i make any request without /content/ I should get a 404.

In both cases the file is in the same path on disk but the path of the http request changes accordingly to the parameter, this is useful for angular applications where the base-href is set.

ng serve has the parameter --serve-path for this functionality.

@it180171
Copy link

sdyffdsaf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants