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

Run app with an URL prefix #643

Closed
qin-nz opened this issue Nov 15, 2021 · 5 comments
Closed

Run app with an URL prefix #643

qin-nz opened this issue Nov 15, 2021 · 5 comments

Comments

@qin-nz
Copy link

qin-nz commented Nov 15, 2021

Hi everyone,
I have an http reverse proxy (e.g. nginx) before the go-app server. It can forward a fixed prefix (e.g. mygoapp) and only forward this prefix to my server.

That means only request with prefix /mygoapp can be handled.

For example,

  • home page should be http://example.com/mygoapp
  • path http://example.com/web/app.wasm should be http://example.com/mygoapp/web/app.wasm.

It's possible to run go-app in this environment ?

@maxence-charriere
I tried this (modified on example in README.md), and open http://example.com/mygoapp, but got 404 page not found

	http.Handle("/mygoapp", http.StripPrefix("/mygoapp", &app.Handler{
		Name:        "Hello",
		Description: "An Hello World! example",
	}))
@maxence-charriere
Copy link
Owner

maxence-charriere commented Nov 15, 2021

I m not sure to understand what you are asking,
Both path should be possible to use. The second one should be the natural one.

@YankeeTube
Copy link

YankeeTube commented Nov 17, 2021

I am experiencing similar problems.
I want to create a jam stack using go-app and Vite.js, and the app.wasm file keeps being requested through the /web/app.wasm path.

https://go-app.dev/static-resources#setup-local-web-directory

@maxence-charriere
I want to allow the user to set the path of the app.wasm file. /web/ Can I change it without being fixed to the directory?

@flyn-org
Copy link

flyn-org commented Apr 3, 2024

I would be interested to hear if either @qin-nz or @YankeeTube figured this out. I, too, am trying to run a go-app behind a reverse proxy.

I got almost there by setting my handler's Resources field to app.CustomProvider(rootDir, prefix), where rootDir is the path to my web files and prefix is "mygoapp" from "http://example.com/mygoapp/...". I found adding the "mygoapp/" prefix to the go-app/h.cachedPWAResources.Set() calls in [email protected]/pkg/app/http.go allowed the application to serve app.js, app.css, and wasm_exec.js.*

But app.wasm is the sticking point. No matter what I do I cannot figure out how to serve that file when the HTTP GETs come prefixed with /mygoapp.

.* Obviously a kludge. I am searching for the correct solution.

@flyn-org
Copy link

flyn-org commented Apr 4, 2024

I figured this out, and I now have my application running behind a lighttpd reverse proxy.

  1. Use http.StripPrefix, as indicated in the initial comment of this issue to strip the prefixes /P from the requests sent to the client/pre-render code by way of the handler.
  2. Set the app.Handler's Resources field to the result of app.CustomProvider(rootDir, "/P"). The value of rootDir is the directory containing the web directory, allowing the server to run with its working directory elsewhere. "/P" ensures references sent back to the browser do contain "/P".
  3. Ensure your server-side routes include /P.
  4. Ensure your client-side routes do not include /P.

Getting this to work is a little fragile, but once I figured it out it made sense. I can see why this might seem obvious in hindsight. I might tack a crack at adding this to the documentation if I can figure out a way to clearly describe it.

@flyn-org
Copy link

flyn-org commented Apr 5, 2024

Related: #944.

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