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

[feature request] add an ability to serve SPA (single page application) app #474

Closed
azzamsa opened this issue Mar 22, 2021 · 9 comments · Fixed by #515
Closed

[feature request] add an ability to serve SPA (single page application) app #474

azzamsa opened this issue Mar 22, 2021 · 9 comments · Fixed by #515

Comments

@azzamsa
Copy link

azzamsa commented Mar 22, 2021

Hi.

IMHO. miniserve doesn't able to serve SPA app.
Below is the demo. quiz-seed is quiz app built using seed.rs.

quiz-seed/dist on  master [!?] via ⬢ v14.15.4
❯ miniserve . --index index.html

03:37:11 [ERROR] Route /quiz could not be found
03:37:14 [ERROR] Route /point could not be found
03:37:15 [ERROR] Route /browser-sync/socket.io/ could not be found
03:37:21 [ERROR] Route /browser-sync/socket.io/ could not be found
03:37:27 [ERROR] Route /browser-sync/socket.io/ could not be found
03:37:33 [ERROR] Route /browser-sync/socket.io/ could not be found
03:37:39 [ERROR] Route /browser-sync/socket.io/ could not be found
^C⏎

In the browser:

azra-quiz-miniserve

I tried the same step with python3 -m http.server 8080 and had the same result as miniserve.
It can't find quiz and point page.


Here I try using local-web-server.js
It has --spa parameter.

quiz-seed on  master [!?] is 📦 v0.1.0 via ⬢ v14.15.4 via 🦀 v1.50.0
❯ yarn global add local-web-server

quiz-seed/dist on  master [!?] via ⬢ v14.15.4 took 3s
❯ ws --spa index.html
Listening on http://debianm:8000, http://127.0.0.1:8000, http://192.168.8.101:8000
^C⏎   

In the browser:

azra-quiz-ws

Thanks for miniserve!

@svenstaro
Copy link
Owner

Hm, yeah for SPAs it's not quite clear that one shouldn't really currently use --index as it is right now. I suppose for an SPA you'd simply provide the path to the files and then just navigate there. I'm not sure --index should allow you to access other files as well. Perhaps we could have two flags.

@azzamsa
Copy link
Author

azzamsa commented Mar 22, 2021

I also tried using:

  • ❯ miniserve index.html
  • ❯ miniserve .

Both had similar result:

quiz-seed/dist on  master [!?] via ⬢ v14.15.4
❯ miniserve index.html

Quit by pressing CTRL-C
01:54:24 [ERROR] Route /compiled-dff33da8ba754e62.css could not be found
01:54:24 [ERROR] Route /index-f7adbebf1e2a9498.js could not be found
01:54:37 [ERROR] Route /compiled-dff33da8ba754e62.css could not be found
01:54:37 [ERROR] Route /index-f7adbebf1e2a9498.js could not be found

In browser:

GEThttp://127.0.0.1:8080/compiled-dff33da8ba754e62.css
[HTTP/1.1 404 Not Found 0ms]

GEThttp://127.0.0.1:8080/index-f7adbebf1e2a9498.js
[HTTP/1.1 404 Not Found 0ms]

Loading module from “http://127.0.0.1:8080/index-f7adbebf1e2a9498.js” was blocked because of a disallowed MIME type (“”). 127.0.0.1:8080
GEThttp://127.0.0.1:8080/favicon.ico
[HTTP/1.1 500 Internal Server Error 0ms]

Using miniserve .

azra-quiz-miniserve-titik

Using miniserve index.html (completely blank)

azra-quiz-miniserve-index

@svenstaro
Copy link
Owner

That's interesting. I host plenty of SPAs using miniserve by simply providing the path to the application root. Will have to investigate. Might actually be the MIME types from the looks of it.

@azzamsa
Copy link
Author

azzamsa commented Mar 22, 2021

Thanks!

Fyi. I tried other app. microserver. It works out of the box.

quiz-seed/dist on  master [$!?] via ⬢ v14.15.4 took 15s
❯ microserver . --port 8000

This is the dist in case you need to investigate it further.

dist.zip

@koalp
Copy link

koalp commented Mar 27, 2021

Isn't the issue that it is not possible to define a fallback index ? ( same as #192 )

Due to this issue I use simple-http-server with the --try-file option to serve single page applications.

@svenstaro
Copy link
Owner

Related actix/actix-web#2115

@ngirard
Copy link
Contributor

ngirard commented Oct 31, 2021

Nice work !

This deserves to be documented in the README, IMHO.

@svenstaro
Copy link
Owner

I documented the new stuff in the README.

@ngirard
Copy link
Contributor

ngirard commented Oct 31, 2021

Great, thanks !

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

Successfully merging a pull request may close this issue.

4 participants