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

Serve other static index.html and assets on subpath(s)? #757

Open
chris-dura opened this issue Feb 10, 2023 · 9 comments
Open

Serve other static index.html and assets on subpath(s)? #757

chris-dura opened this issue Feb 10, 2023 · 9 comments

Comments

@chris-dura
Copy link

chris-dura commented Feb 10, 2023

Description

I basically have 3 "apps", each are "static" bundles with their own relative assets.

my-app/
├── app2/
│   ├── app2.js
│   └── index.html
├── app3/
│   ├── index.css
│   └── app3.js
├── index.html
└── my-app.js

When I run serve -l 5280 my-app, I can browse to http://localhost:5280 and it serves my-app/index.html and the my-app.js just fine.

However, when I type http://localhost:5280/app2 in the address bar, the app2/index.html loads, but I get a 404 on app2.js :/

Library version

v14.2.0

Node version

v16.17.0

@aasen
Copy link

aasen commented Mar 28, 2023

I have the same issue.

@yairEO
Copy link

yairEO commented Mar 31, 2023

Even if you will directly run serve app2/index.html you'll get 404 for the assets (but the HTML itself will be served...)

@chris-dura
Copy link
Author

Even if you will directly run serve app2/index.html you'll get 404 for the assets (but the HTML itself will be served...)

... do you mean serve my-app/app2? Because, it should get the assets just fine in that case, since app2/index.html has relative asset URLs... eg, <script src="./app2.js"/>

@yairEO
Copy link

yairEO commented Apr 2, 2023

No, I mean, if you directly serve an .html file, all its assets return 404

@chris-dura
Copy link
Author

No, I mean, if you directly serve an .html file, all its assets return 404

fwiw, all the docs and examples show serving folders, not a single .html file, so this might not be a supported usage? 🤷

$ serve my-app/path/to/some/index.html

... but I would expect this to work (and in my experience it does 🤷🏻)

$ serve my-app/path/to/some

@yairEO
Copy link

yairEO commented Apr 9, 2023

@chris-dura - I do not want to serve folders in any way. I only need to serve single files:

serve my-app/path/to/some/1.html
serve my-app/path/to/some/2.html
serve my-app/path/to/some/3.html

And so on. These files have assets which cannot be loaded due to 404

@chris-dura
Copy link
Author

@yairEO -- Right, there's nothing in the docs that indicate serving single files like that would be supported.

I understand if there's a reason you can't do this, but if you change them to index.html files...

my-app/path/to/some/1/index.html
my-app/path/to/some/2/index.html
my-app/path/to/some/3/index.html

... then this would work out-of-the-box with no extra configuration ...

serve my-app/path/to/some/1
serve my-app/path/to/some/2
serve my-app/path/to/some/3

You might also be able to configure some redirects/rewrites in serve.json.

@yairEO
Copy link

yairEO commented Apr 12, 2023

I cannot change them to index.html because they are all in the same folder and cannot be moved. Also, the name of the html files is important.

I am using http-server which can do this extremely simple thing, which serve cannot.

@ultravires
Copy link

I have the same issue.

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

No branches or pull requests

4 participants