Compare commits

..

3 Commits

Author SHA1 Message Date
b61bf52df9 fix(module,net): add missing context to server message
fix #6
2023-03-03 10:43:13 +01:00
f1dd467c95 fix(doc): typo 2023-03-01 15:15:47 +01:00
3136d71032 feat(http): handle html5 routing
ref #5
2023-03-01 14:39:45 +01:00
6 changed files with 66 additions and 9 deletions

View File

@ -178,6 +178,6 @@ var results = store.query(ctx, "myCollection", {
limit: 10,
offset: 5,
orderBy: "foo",
orderDirection: store.ASC,
orderDirection: store.DIRECTION_ASC,
});
```

View File

@ -4,7 +4,7 @@
<meta charset="utf-8" />
<title>Client SDK Test suite</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="vendor/mocha.css" />
<link rel="stylesheet" href="/vendor/mocha.css" />
<style>
body {
background-color: white;
@ -13,15 +13,15 @@
</head>
<body>
<div id="mocha"></div>
<script src="vendor/chai.js"></script>
<script src="vendor/mocha.js"></script>
<script src="/vendor/chai.js"></script>
<script src="/vendor/mocha.js"></script>
<script class="mocha-init">
mocha.setup('bdd');
mocha.checkLeaks();
</script>
<script src="/edge/sdk/client.js"></script>
<script src="test/client-sdk.js"></script>
<script src="test/auth-module.js"></script>
<script src="/test/client-sdk.js"></script>
<script src="/test/auth-module.js"></script>
<script class="mocha-exec">
mocha.run();
</script>

View File

@ -99,3 +99,5 @@ func (f *File) Readdir(count int) ([]os.FileInfo, error) {
func (f *File) Stat() (os.FileInfo, error) {
return f.fi, nil
}
var _ http.FileSystem = &FileSystem{}

View File

@ -59,7 +59,7 @@ func (h *Handler) Load(bdle bundle.Bundle) error {
}
fs := bundle.NewFileSystem("public", bdle)
public := http.FileServer(fs)
public := HTML5Fileserver(fs)
sockjs := sockjs.NewHandler(sockJSPathPrefix, h.sockjsOpts, h.handleSockJSSession)
if h.server != nil {

View File

@ -0,0 +1,54 @@
package http
import (
"net/http"
"os"
"path"
"strings"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
func HTML5Fileserver(fs http.FileSystem) http.Handler {
handler := http.FileServer(fs)
fn := func(w http.ResponseWriter, r *http.Request) {
urlPath := r.URL.Path
if !strings.HasPrefix(urlPath, "/") {
urlPath = "/" + urlPath
r.URL.Path = urlPath
}
urlPath = path.Clean(urlPath)
file, err := fs.Open(urlPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
r.URL.Path = "/"
handler.ServeHTTP(w, r)
return
}
logger.Error(r.Context(), "could not open bundle file", logger.E(err))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
defer func() {
if err := file.Close(); err != nil {
logger.Error(r.Context(), "could not close file", logger.E(err))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}()
handler.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}

View File

@ -38,9 +38,10 @@ func (m *Module) broadcast(call goja.FunctionCall, rt *goja.Runtime) goja.Value
}
data := call.Argument(0).Export()
ctx := context.Background()
msg := module.NewServerMessage(nil, data)
if err := m.bus.Publish(context.Background(), msg); err != nil {
msg := module.NewServerMessage(ctx, data)
if err := m.bus.Publish(ctx, msg); err != nil {
panic(rt.ToValue(errors.WithStack(err)))
}