@dimina-kit/devkit 0.1.0-dev.20260422094158 → 0.1.0-dev.20260424074115
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/fe/index.js +21 -5
- package/package.json +1 -1
package/fe/index.js
CHANGED
|
@@ -76,11 +76,27 @@ export async function start({ port = 7788, containerDir, outputDir, simulatorDir
|
|
|
76
76
|
// Load proxy server middleware (cors, json, /proxy route)
|
|
77
77
|
await import('./dimina-fe-server/index.js')
|
|
78
78
|
|
|
79
|
-
// SPA fallback: serve index.html for
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
// SPA fallback: serve index.html for navigation-like unmatched routes
|
|
80
|
+
// (no extension or `.html`). Asset-like misses (`.json`, `.js`, `.wxml`,
|
|
81
|
+
// `.css`, source maps, …) must return a real 404 — never HTML. The
|
|
82
|
+
// container's runtime does
|
|
83
|
+
// fetch(url).then(r => r.text()).then(JSON.parse)
|
|
84
|
+
// for manifests like `<appId>/main/app-config.json`, and serving the SPA
|
|
85
|
+
// shell for such a miss makes `initApp()` die with
|
|
86
|
+
// `SyntaxError: Unexpected token '<', "<!doctype "…` inside an un-
|
|
87
|
+
// handled promise rejection.
|
|
88
|
+
// Express 5 requires a named wildcard parameter instead of bare '*'.
|
|
89
|
+
const spaFallback = liveReload
|
|
90
|
+
? liveReloadModule.injectScript(containerDir)
|
|
91
|
+
: (_req, res) => res.sendFile('index.html', { root: containerDir })
|
|
92
|
+
|
|
93
|
+
app.get('/{*path}', (req, res, next) => {
|
|
94
|
+
const ext = path.extname(req.path).toLowerCase()
|
|
95
|
+
if (ext && ext !== '.html') {
|
|
96
|
+
res.status(404).type('text/plain').set('cache-control', 'no-store').send('Not Found')
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
return spaFallback(req, res, next)
|
|
84
100
|
})
|
|
85
101
|
|
|
86
102
|
return new Promise((resolve, reject) => {
|