refactor: move Wasm related code to pkg/common/wasm

This commit is contained in:
Prad Nukala 2024-12-11 12:26:48 -05:00
parent d667c3c604
commit 23f077ce75
4 changed files with 11 additions and 10 deletions

View File

@ -9,13 +9,14 @@ import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/vault"
"github.com/onsonr/sonr/internal/vault/types"
"github.com/onsonr/sonr/pkg/common/wasm"
"github.com/onsonr/sonr/pkg/config/motr"
"github.com/onsonr/sonr/pkg/didauth/controller"
)
var (
env *types.Environment
config *types.Config
env *motr.Environment
config *motr.Config
err error
)
@ -47,8 +48,8 @@ func main() {
js.Global().Set("processConfig", js.FuncOf(processConfig))
e := echo.New()
e.Use(vault.WasmContextMiddleware)
e.Use(wasm.ContextMiddleware)
e.Use(controller.Middleware(nil))
vault.RegisterRoutes(e, config)
vault.ServeFetch(e)
wasm.ServeFetch(e)
}

View File

@ -8,10 +8,10 @@ import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/vault/context"
"github.com/onsonr/sonr/internal/vault/types"
"github.com/onsonr/sonr/pkg/config/motr"
)
// RegisterRoutes registers the Decentralized Web Node API routes.
func RegisterRoutes(e *echo.Echo, config *types.Config) {
func RegisterRoutes(e *echo.Echo, config *motr.Config) {
e.Use(context.Middleware(config))
}

View File

@ -1,7 +1,7 @@
//go:build js && wasm
// +build js,wasm
package vault
package wasm
import (
"bytes"

View File

@ -1,7 +1,7 @@
//go:build js && wasm
// +build js,wasm
package vault
package wasm
import (
"encoding/base64"
@ -10,7 +10,7 @@ import (
"github.com/labstack/echo/v4"
)
func WasmContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
func ContextMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// Extract WASM context from headers
if wasmCtx := c.Request().Header.Get("X-Wasm-Context"); wasmCtx != "" {