@rip-lang/server 1.3.3 → 1.3.4

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.
Files changed (2) hide show
  1. package/middleware.rip +8 -3
  2. package/package.json +1 -1
package/middleware.rip CHANGED
@@ -521,10 +521,11 @@ 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 (cached, rebuilt on file change)
525
- bundleCache = { json: null, etag: null }
524
+ # Route: {prefix}/bundle — all components + app data as JSON (cached + Brotli)
525
+ bundleCache = { json: null, br: null, etag: null }
526
526
 
527
527
  buildBundle = ->
528
+ { brotliCompressSync } = require 'zlib'
528
529
  glob = new Bun.Glob("**/*.rip")
529
530
  components = {}
530
531
  for path in Array.from(glob.scanSync(routesDir)).sort()
@@ -539,13 +540,17 @@ export serve = (opts = {}) ->
539
540
  if appState
540
541
  data[k] = v for k, v of appState
541
542
  bundleCache.json = JSON.stringify({ components, data })
543
+ bundleCache.br = brotliCompressSync(bundleCache.json)
542
544
  bundleCache.etag = "W/\"#{Bun.hash(bundleCache.json).toString(36)}\""
543
545
 
544
546
  get "#{prefix}/bundle", (c) ->
545
547
  buildBundle! unless bundleCache.json
546
548
  if c.req.header('if-none-match') is bundleCache.etag
547
549
  return new Response(null, { status: 304, headers: { 'ETag': bundleCache.etag, 'Cache-Control': 'no-cache' } })
548
- new Response bundleCache.json, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': bundleCache.etag }
550
+ useBr = (c.req.header('accept-encoding') or '').includes('br')
551
+ headers = { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'ETag': bundleCache.etag }
552
+ headers['Content-Encoding'] = 'br' if useBr
553
+ new Response (if useBr then bundleCache.br else bundleCache.json), { headers }
549
554
 
550
555
  # Register watch directories with rip-server via control socket
551
556
  if enableWatch and process.env.SOCKET_PREFIX
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/server",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Pure Rip web framework and application server",
5
5
  "type": "module",
6
6
  "main": "api.rip",