-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Custom Handler #504
Comments
Any code example of what you would like to do ? |
Just a note that it is a standard HTTP handler, you can either decorate or override it and get a lot of fine-grained control. |
In my case, I want to handle what is done in
When not using the |
I m curious about how you would do that. You still would have to serve wasm_exec.js somewhere on the server side. What would be the value to serve your own one in a custom handler ? (And as i said, nothing stop you to override the handler or decorate it) |
For the error you get its likely that you must define goappGetEnv func in a js file that is loaded before the wasm file. The thing this that you would have to override both app.js and wasm_exec.js. But again what is the value to have your own one? Those 2 are required to load the wasm file in the browser and having them here is what makes using this package way easier than if you handle it yourself like in the Go wasm tutorials. |
I can't argue for a great reason other than giving power users more options. Using #501 as an example, if using a custom handler were easier I could just handle this myself. I get that |
The issue seems to be more an app.js issue than a custom handler issue. But app.js is part of the core of the package. Kind of feel natural that overriding it requires a little more than just changing the handler for that given endpoint. Edit: also even though the package is not using embed yet, core file for running wasm are already embedded in the code. The usecase i see that fit this issue would be to handle static resources from web directory. For now, this can Be done by registering a handler for /web/ that uses whatever you want. |
Here is my scene. I found that |
@ppphp I would need more context to understand your problem. |
Our kubernetes dispatches the HTTP traffic by adding a |
@ppphp func CustomProvider(root, pathPrefix string) ResourceProvider {
root = strings.Trim(root, "/")
pathPrefix = "/" + strings.Trim(pathPrefix, "/")
return localDir{
Handler: http.FileServer(http.Dir(root)),
root: pathPrefix,
appWASM: pathPrefix + "/web/app.wasm",
}
}
type customProvider struct {
http.Handler
root string
appWASM string
}
func (d customProvider) Package() string {
return d.root
}
func (d customProvider) Static() string {
return d.root
}
func (d customProvider) AppWASM() string {
return d.appWASM
} Then in the Handler: func main() {
// ...
h := &app.Handler{
Resources: CustomProvider("", "YOUR_SERVICE_NAME"),
}
// ...
} Let me know if it works. |
@maxence-charriere It works! |
However, it shows 404 when I visit the index page It is a 404 in go-app application, and the response of /servicename is a page with correct html elements |
when you show the page source, do you see that your UI code is here? |
Oh, I know it. It is a 404 on the web-app route, I will try to fix it. |
Not this one, this is already replaced by the not found code. |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta httpequiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content>
<meta name="description" content="An Hello World! example">
<meta name="keywords" content>
<meta name="theme-color" content="#2d2c2c">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover">
<meta property="og:url" content="http://0.0.0.0:8080/servicename">
<meta property="og:title" content="servicename">
<meta property="og:description" content="An Hello World! example">
<meta property="og:type" content="website">
<meta property="og:image" content>
<title>
servicename
</title>
<link rel="icon" type="image/png" href="https://storage.googleapis.com/murlok-github/icon-192.png">
<link rel="apple-touch-icon" href="https://storage.googleapis.com/murlok-github/icon-192.png">
<link rel="manifest" href="/manifest.webmanifest">
<link href="/app.css" type="text/css" rel="stylesheet">
<script defer src="/wasm_exec.js"></script>
<script defer src="/app.js"></script>
</head>
<body>
<div>
<div id="app-pre-render">
<div>
<h1>
calculate:
</h1>
show account 0 =
<h1>
select user:
</h1>
<form>
<input placeholder>
<button>
submit
</button>
</form>
</div>
</div>
<div id="app-wasm-loader" class="goapp-app-info">
<img id="app-wasm-loader-icon" class="goapp-logo goapp-spin" src="https://storage.googleapis.com/murlok-github/icon-192.png">
<p id="app-wasm-loader-label" class="goapp-label">
Loading
</p>
</div>
</div>
<div id="app-end"></div>
</body>
</html> |
I think I found the problem. Can you try this branch:
|
It works again! |
All right can you hang a little bit with this branch? I'll release a proper version by the end of the week. |
Sure. Thank you for your help. |
@ppphp Just push v8.0.2 that fixes the problem. |
Still thinking that this can be solved with http.Handler decorator. Closing this for now. |
It would be nice if
app
made it easier to work with a customHandler
. For cases like #501 , I could implement my own handler and have fine grained control.The text was updated successfully, but these errors were encountered: