http-party / http-server

a simple zero-configuration command-line http server
MIT License
13.42k stars 1.48k forks source link

Support relative path prefixes (base in vite.config.js) #866

Closed tommed closed 8 months ago

tommed commented 8 months ago

I am trying to deploy a UI which is accessed from a relative path rather than root directory:

https://MY_DOMAIN.TLD/london/fileshare

To achieve this, I have a relative path set in my VueJS vite.config.js file:

export default defineConfig({
  base: '/london/fileshare',
  // ...
}

However, when it comes to serving the web site, all requests (including static file requests like https://MY_DOMAIN/london/fileshare/assets/index-c9fdd385.css return index.html because it's clearly looking for a static file at london/fileshare/assets/index-c9fdd385.css rather than assets/index-c9fdd385.css. This is because there is no way to tell the web server this is being accessed from a local path.

If I omit the base value from vite.config.js, it renders the assets to /assets/index-c9fdd385.css and the root directory is obviously outside of the application so will fail too.

Clearly the web server just needs to be aware of the relative path prefix?

Environment Versions

  1. OS Type macOS and ubuntu/node docker images - it's a conceptual problem which exists regardless of OS
  2. Node version: $ node --version :latest docker image

Steps to reproduce

  1. Set relative base path in vite.config.js
  2. npm run build host in a http-server process
  3. Make a request and watch the .css and .js requests fail to connect to the static files

Expected result

Be able to inform the http-server about the relative path, and for it not to be included when locating static content.

Actual result

http-server is using the relative path prefix when looking for local static file content, it should instead be trimming this from the request path first.

zbynek commented 8 months ago

See #294, #139, #595, ...

Also: AFAIK there are just 2 people with maintainer access of this project and neither of them has shown any interest in the last year, so you might be better off switching to serve, which supports rewrites: https://github.com/vercel/serve-handler#rewrites-array

tommed commented 8 months ago

Yikes, such as shame. Let's hope our new AI overlords don't get bored so easily 🤣 I read somewhere that 45% of code written on GitHub is now AI generated?!