go-app
go-app copied to clipboard
Run app with an URL prefix
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 behttp://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",
}))
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.
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?
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.
I figured this out, and I now have my application running behind a lighttpd reverse proxy.
- 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. - Set the
app.Handler
'sResources
field to the result ofapp.CustomProvider(rootDir, "/P")
. The value ofrootDir
is the directory containing theweb
directory, allowing the server to run with its working directory elsewhere."/P"
ensures references sent back to the browser do contain"/P"
. - Ensure your server-side routes include
/P
. - 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.
Related: https://github.com/maxence-charriere/go-app/pull/944.