baraqex 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Baraqex Full-Stack App</title>
|
|
7
|
+
<link rel="icon" href="data:,">
|
|
7
8
|
<link rel="stylesheet" href="/build/styles.css">
|
|
8
9
|
<script>window.__INITIAL_STATE__ = {};</script>
|
|
9
10
|
</head>
|
|
@@ -57,16 +57,20 @@ app.get('/api/users', (req, res) => {
|
|
|
57
57
|
res.json(store.users);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
app.get('/api/users/:id', (req, res) => {
|
|
60
|
+
app.get('/api/users/:id', (req: Request, res: Response) => {
|
|
61
61
|
const user = store.users.find((u) => u.id === parseInt(req.params.id, 10));
|
|
62
|
-
if (user)
|
|
62
|
+
if (user) {
|
|
63
|
+
res.json(user);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
63
66
|
res.status(404).json({ error: 'User not found' });
|
|
64
67
|
});
|
|
65
68
|
|
|
66
|
-
app.get('/api/posts', (req, res) => {
|
|
69
|
+
app.get('/api/posts', (req: Request, res: Response) => {
|
|
67
70
|
const { authorId } = req.query;
|
|
68
71
|
if (authorId) {
|
|
69
|
-
|
|
72
|
+
res.json(store.posts.filter((p) => p.authorId === parseInt(authorId as string, 10)));
|
|
73
|
+
return;
|
|
70
74
|
}
|
|
71
75
|
res.json(store.posts);
|
|
72
76
|
});
|
|
@@ -134,6 +138,20 @@ async function buildStyles() {
|
|
|
134
138
|
// Build the Tailwind stylesheet used by the SSR-rendered page (both modes)
|
|
135
139
|
await buildStyles();
|
|
136
140
|
|
|
141
|
+
// In dev, bundle the client with esbuild (rebuilds on change via the watcher below)
|
|
142
|
+
if (isDev) {
|
|
143
|
+
await setupEsbuild();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Only load the Go runtime scripts when the WASM module has been built
|
|
147
|
+
// (`npm run build:wasm` requires Go). Off by default so dev works without Go.
|
|
148
|
+
const hasWasm = existsSync(path.join(__dirname, 'public', 'wasm', 'example.wasm'))
|
|
149
|
+
&& existsSync(path.join(__dirname, 'public', 'wasm', 'wasm_exec.js'));
|
|
150
|
+
|
|
151
|
+
const wasmScripts = hasWasm
|
|
152
|
+
? '<script src="/wasm/wasm_exec.js"></script>'
|
|
153
|
+
: '<script>console.warn("Go WASM not built — run `npm run build:wasm` (requires Go)");</script>';
|
|
154
|
+
|
|
137
155
|
// ---------------------------------------------------------------------------
|
|
138
156
|
// SSR: render the App on the server, then hydrate on the client
|
|
139
157
|
// ---------------------------------------------------------------------------
|
|
@@ -160,11 +178,12 @@ app.get('*', async (req: Request, res: Response, next: NextFunction) => {
|
|
|
160
178
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
161
179
|
<title>Baraqex Full-Stack App (SSR + WASM + Go)</title>
|
|
162
180
|
<link rel="stylesheet" href="/build/styles.css">
|
|
181
|
+
<link rel="icon" href="data:,">
|
|
163
182
|
<script>window.__INITIAL_STATE__ = ${JSON.stringify(initialState)};</script>
|
|
164
183
|
</head>
|
|
165
184
|
<body>
|
|
166
185
|
<div id="root">${content}</div>
|
|
167
|
-
|
|
186
|
+
${wasmScripts}
|
|
168
187
|
${isDev ? '<script src="/socket.io/socket.io.js"></script>' : ''}
|
|
169
188
|
<script src="/build/main.js" type="module"></script>
|
|
170
189
|
</body>
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"target": "ES2020",
|
|
4
4
|
"module": "ESNext",
|
|
5
5
|
"moduleResolution": "Bundler",
|
|
6
|
-
"jsx": "
|
|
6
|
+
"jsx": "react",
|
|
7
|
+
"jsxFactory": "jsx",
|
|
8
|
+
"jsxFragmentFactory": "Fragment",
|
|
7
9
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
8
10
|
"strict": true,
|
|
9
11
|
"esModuleInterop": true,
|