@rip-lang/server 1.3.0 → 1.3.2
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/api.rip +2 -1
- package/middleware.rip +16 -14
- package/package.json +1 -1
- package/server.rip +2 -1
package/api.rip
CHANGED
|
@@ -156,8 +156,9 @@ createContext = (req, params = {}) ->
|
|
|
156
156
|
file = Bun.file(path)
|
|
157
157
|
etag = "W/\"#{file.lastModified}-#{file.size}\""
|
|
158
158
|
if req.headers.get('if-none-match') is etag
|
|
159
|
-
return new Response(null, { status: 304, headers: { 'ETag': etag } })
|
|
159
|
+
return new Response(null, { status: 304, headers: { 'ETag': etag, 'Cache-Control': 'no-cache' } })
|
|
160
160
|
out.set 'Content-Type', (type or mimeType(path))
|
|
161
|
+
out.set 'Cache-Control', 'no-cache'
|
|
161
162
|
out.set 'ETag', etag
|
|
162
163
|
new Response file, { status: 200, headers: out }
|
|
163
164
|
|
package/middleware.rip
CHANGED
|
@@ -521,36 +521,38 @@ export serve = (opts = {}) ->
|
|
|
521
521
|
name = c.req.path.slice("#{prefix}/components/".length)
|
|
522
522
|
c.send "#{routesDir}/#{name}", 'text/plain; charset=UTF-8'
|
|
523
523
|
|
|
524
|
-
# Route: {prefix}/bundle — all components + app data as JSON
|
|
525
|
-
|
|
524
|
+
# Route: {prefix}/bundle — all components + app data as JSON (cached, rebuilt on file change)
|
|
525
|
+
bundleCache = { json: null, etag: null }
|
|
526
|
+
|
|
527
|
+
buildBundle = ->
|
|
526
528
|
glob = new Bun.Glob("**/*.rip")
|
|
527
529
|
components = {}
|
|
528
|
-
|
|
529
|
-
for path in paths
|
|
530
|
+
for path in Array.from(glob.scanSync(routesDir)).sort()
|
|
530
531
|
components["components/#{path}"] = Bun.file("#{routesDir}/#{path}").text!
|
|
531
|
-
|
|
532
532
|
for dir in componentDirs
|
|
533
|
-
|
|
534
|
-
for path in incPaths
|
|
533
|
+
for path in Array.from(glob.scanSync(dir)).sort()
|
|
535
534
|
key = "components/_lib/#{path}"
|
|
536
535
|
components[key] = Bun.file("#{dir}/#{path}").text! unless components[key]
|
|
537
|
-
|
|
538
536
|
data = {}
|
|
539
537
|
data.title = appTitle if appTitle
|
|
540
538
|
data.watch = enableWatch
|
|
541
539
|
if appState
|
|
542
540
|
data[k] = v for k, v of appState
|
|
541
|
+
bundleCache.json = JSON.stringify({ components, data })
|
|
542
|
+
bundleCache.etag = "W/\"#{Bun.hash(bundleCache.json).toString(36)}\""
|
|
543
|
+
|
|
544
|
+
buildBundle!
|
|
543
545
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if c.req.header('if-none-match') is etag
|
|
547
|
-
return new Response(null, { status: 304, headers: { 'ETag': etag } })
|
|
548
|
-
new Response json, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': etag }
|
|
546
|
+
get "#{prefix}/bundle", (c) ->
|
|
547
|
+
buildBundle! unless bundleCache.json
|
|
548
|
+
if c.req.header('if-none-match') is bundleCache.etag
|
|
549
|
+
return new Response(null, { status: 304, headers: { 'ETag': bundleCache.etag, 'Cache-Control': 'no-cache' } })
|
|
550
|
+
new Response bundleCache.json, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': bundleCache.etag }
|
|
549
551
|
|
|
550
552
|
# Register watch directories with rip-server via control socket
|
|
551
553
|
if enableWatch and process.env.SOCKET_PREFIX
|
|
552
554
|
ctl = "/tmp/#{process.env.SOCKET_PREFIX}.ctl.sock"
|
|
553
|
-
dirs = [routesDir, ...componentDirs, "#{appDir}/css"]
|
|
555
|
+
dirs = [routesDir, ...componentDirs, "#{appDir}/css"].filter existsSync
|
|
554
556
|
body = JSON.stringify({ op: 'watch', prefix, dirs })
|
|
555
557
|
fetch('http://localhost/watch', { method: 'POST', body, headers: { 'content-type': 'application/json' }, unix: ctl }).catch (e) ->
|
|
556
558
|
console.warn "[Rip] Watch registration failed: #{e.message}"
|
package/package.json
CHANGED
package/server.rip
CHANGED
|
@@ -591,7 +591,8 @@ class Manager
|
|
|
591
591
|
broadcast('css')
|
|
592
592
|
watchers.push(w)
|
|
593
593
|
catch e
|
|
594
|
-
|
|
594
|
+
rel = dir.replace(process.cwd() + '/', '')
|
|
595
|
+
console.warn "rip-server: watch skipped (#{e.code or 'error'}): #{rel}"
|
|
595
596
|
@appWatchers.set prefix, { watchers, timer }
|
|
596
597
|
|
|
597
598
|
spawnWorker: (version) ->
|