Skip to content

Commit d6e2d7f

Browse files
committed
revert: remove SSR support
1 parent 74f52d6 commit d6e2d7f

File tree

15 files changed

+29
-825
lines changed

15 files changed

+29
-825
lines changed

cmd/rfw/build/build.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,29 @@ import (
1515
_ "github.com/rfwlab/rfw/cmd/rfw/plugins/test"
1616
)
1717

18-
func Build(_ map[string]any) error {
19-
var manifest struct {
20-
Build struct {
21-
Type string `json:"type"`
22-
OutDir string `json:"outDir"`
23-
} `json:"build"`
24-
Plugins map[string]json.RawMessage `json:"plugins"`
25-
}
26-
if data, err := os.ReadFile("rfw.json"); err == nil {
27-
_ = json.Unmarshal(data, &manifest)
28-
}
29-
30-
outDir := "."
31-
clientDir := filepath.Join(outDir, "")
32-
if manifest.Build.Type == "ssr" {
33-
outDir = manifest.Build.OutDir
34-
if outDir == "" {
35-
outDir = "dist"
36-
}
37-
clientDir = filepath.Join(outDir, "client")
38-
if err := os.MkdirAll(clientDir, 0o755); err != nil {
39-
return err
40-
}
41-
}
42-
18+
func Build() error {
4319
goroot, err := exec.Command("go", "env", "GOROOT").Output()
4420
if err != nil {
4521
return fmt.Errorf("failed to get GOROOT: %w", err)
4622
}
4723
wasmExec := filepath.Join(strings.TrimSpace(string(goroot)), "lib", "wasm", "wasm_exec.js")
48-
if err := copyFile(wasmExec, filepath.Join(clientDir, "wasm_exec.js")); err != nil {
24+
if err := copyFile(wasmExec, "wasm_exec.js"); err != nil {
4925
return fmt.Errorf("failed to copy wasm_exec.js: %w", err)
5026
}
5127

52-
outputWasm := filepath.Join(clientDir, "app.wasm")
53-
cmd := exec.Command("go", "build", "-o", outputWasm, "main.go")
28+
cmd := exec.Command("go", "build", "-o", "main.wasm", "main.go")
5429
cmd.Env = append(os.Environ(), "GOARCH=wasm", "GOOS=js")
5530
output, err := cmd.CombinedOutput()
5631
if err != nil {
5732
return fmt.Errorf("failed to build project: %s: %w", output, err)
5833
}
5934

35+
var manifest struct {
36+
Plugins map[string]json.RawMessage `json:"plugins"`
37+
}
38+
if data, err := os.ReadFile("rfw.json"); err == nil {
39+
_ = json.Unmarshal(data, &manifest)
40+
}
6041
if err := plugins.Configure(manifest.Plugins); err != nil {
6142
return fmt.Errorf("failed to run plugins: %w", err)
6243
}

cmd/rfw/commands/build.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func NewBuildCommand() *command.Command {
1717
}
1818

1919
func runBuild(cmd *command.Command, _ *command.RootFlags, _ []string) error {
20-
if err := build.Build(nil); err != nil {
21-
return err
22-
}
23-
cmd.Logger.Success("Build completed")
24-
return nil
20+
if err := build.Build(); err != nil {
21+
return err
22+
}
23+
cmd.Logger.Success("Build completed")
24+
return nil
2525
}

cmd/rfw/server/server.go

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"bufio"
5-
"encoding/json"
65
"expvar"
76
"fmt"
87
"net/http"
@@ -17,7 +16,6 @@ import (
1716
"github.com/rfwlab/rfw/cmd/rfw/build"
1817
"github.com/rfwlab/rfw/cmd/rfw/plugins"
1918
"github.com/rfwlab/rfw/cmd/rfw/utils"
20-
"github.com/rfwlab/rfw/v1/ssr"
2119
)
2220

2321
var rebuilds = expvar.NewInt("rebuilds")
@@ -41,66 +39,17 @@ func NewServer(port string, host, debug bool) *Server {
4139
}
4240

4341
func (s *Server) Start() error {
44-
if err := build.Build(nil); err != nil {
42+
if err := build.Build(); err != nil {
4543
return err
4644
}
47-
var manifest struct {
48-
Build struct {
49-
Type string `json:"type"`
50-
OutDir string `json:"outDir"`
51-
} `json:"build"`
52-
}
53-
if data, err := os.ReadFile("rfw.json"); err == nil {
54-
_ = json.Unmarshal(data, &manifest)
55-
}
45+
5646
mux := http.NewServeMux()
57-
if manifest.Build.Type == "ssr" {
58-
outDir := manifest.Build.OutDir
59-
if outDir == "" {
60-
outDir = "dist"
61-
}
62-
clientDir := filepath.Join(outDir, "client")
63-
mux.Handle("/dist/client/", http.StripPrefix("/dist/client/", http.FileServer(http.Dir(clientDir))))
64-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
65-
utils.LogServeRequest(r)
66-
if r.URL.Path != "/" {
67-
http.NotFound(w, r)
68-
return
69-
}
70-
name := r.URL.Query().Get("name")
71-
if name == "" {
72-
name = "World"
73-
}
74-
rendered, err := ssr.RenderFile("index.rtml", map[string]any{"name": name, "count": 0})
75-
if err != nil {
76-
http.Error(w, "failed to render", http.StatusInternalServerError)
77-
return
78-
}
79-
html := fmt.Sprintf(`<!DOCTYPE html>
80-
<html lang="en">
81-
<head>
82-
<meta charset="UTF-8">
83-
<title>RFW</title>
84-
</head>
85-
<body>
86-
<div id="app" data-hydrate>%s</div>
87-
<script src="/dist/client/wasm_exec.js"></script>
88-
<script>
89-
const go = new Go();
90-
WebAssembly.instantiateStreaming( fetch("/dist/client/app.wasm?" + Date.now()), go.importObject, ).then((result) => { go.run(result.instance); });
91-
</script>
92-
</body>
93-
</html>`, rendered)
94-
w.Header().Set("Content-Type", "text/html")
95-
fmt.Fprint(w, html)
96-
})
97-
} else {
98-
fs := http.FileServer(http.Dir("."))
99-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
100-
utils.LogServeRequest(r)
101-
s.handleFileRequest(w, r, fs)
102-
})
103-
}
47+
48+
fs := http.FileServer(http.Dir("."))
49+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
50+
utils.LogServeRequest(r)
51+
s.handleFileRequest(w, r, fs)
52+
})
10453

10554
if s.Debug {
10655
mux.Handle("/debug/vars", expvar.Handler())
@@ -219,7 +168,7 @@ func (s *Server) watchFiles() {
219168
plugins.NeedsRebuild(event.Name)) {
220169
rebuilds.Add(1)
221170
utils.Info("Changes detected, rebuilding...")
222-
if err := build.Build(nil); err != nil {
171+
if err := build.Build(); err != nil {
223172
utils.Fatal("Failed to rebuild project: ", err)
224173
}
225174
}

docs/main.wasm

11.5 MB
Binary file not shown.
-3.62 MB
Binary file not shown.

examples/ssr_example/index.rtml

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/ssr_example/main.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

examples/ssr_example/rfw.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/ssr_example/server/main.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

v1/core/component_host.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,18 @@
22

33
package core
44

5-
// Component defines the minimal interface for SSR-compatible components.
5+
// Component defines the minimal interface exposed to plugins in non-WASM builds.
66
type Component interface {
7-
Render() string
8-
GetName() string
9-
GetID() string
7+
Render() string
8+
GetName() string
9+
GetID() string
1010
}
1111

12-
// ComponentRegistry holds constructors for components available to the SSR renderer.
12+
// ComponentRegistry holds constructors for components available to plugins.
1313
var ComponentRegistry = map[string]func() Component{}
1414

1515
// RegisterComponent registers a component constructor for lookup by name.
1616
func RegisterComponent(name string, constructor func() Component) {
17-
ComponentRegistry[name] = constructor
17+
ComponentRegistry[name] = constructor
1818
}
1919

20-
// NewComponent returns a basic HTMLComponent initialized with the provided template and props.
21-
func NewComponent(name string, templateFS []byte, props map[string]any) *HTMLComponent {
22-
c := NewHTMLComponent(name, templateFS, props)
23-
c.SetComponent(c)
24-
return c
25-
}
26-
27-
// NewComponentWith binds an existing component implementation to the HTMLComponent.
28-
func NewComponentWith[T Component](name string, templateFS []byte, props map[string]any, self T) *HTMLComponent {
29-
c := NewHTMLComponent(name, templateFS, props)
30-
if any(self) != nil {
31-
c.SetComponent(self)
32-
} else {
33-
c.SetComponent(c)
34-
}
35-
return c
36-
}

0 commit comments

Comments
 (0)