@rip-lang/server 1.3.8 → 1.3.10
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 +26 -3
- package/package.json +2 -2
package/api.rip
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
# Server: start, startHandler, fetch, App
|
|
11
11
|
# Filters: raw, before, after
|
|
12
12
|
# Handlers: onError, notFound
|
|
13
|
+
# Errors: error!, notice!, bail!
|
|
13
14
|
# Validation: read, validators, registerValidator, getValidator
|
|
14
15
|
# Context: ctx, session, env, subrequest
|
|
15
16
|
# Utilities: isBlank, toName, toPhone, mimeType
|
|
@@ -185,6 +186,7 @@ createContext = (req, params = {}) ->
|
|
|
185
186
|
else parseInt(duration) or 0
|
|
186
187
|
else 0
|
|
187
188
|
out.set 'Cache-Control', "public, max-age=#{seconds}, immutable"
|
|
189
|
+
out.set 'Expires', new Date(Date.now() + seconds * 1000).toUTCString()
|
|
188
190
|
return
|
|
189
191
|
|
|
190
192
|
session: {}
|
|
@@ -271,8 +273,12 @@ smart = (fn) ->
|
|
|
271
273
|
catch err
|
|
272
274
|
status = err?.status or 500
|
|
273
275
|
console.error 'Handler error:', err if status >= 500
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
if err?.notice
|
|
277
|
+
body = JSON.stringify { error: { notice: err.notice } }
|
|
278
|
+
new Response body, { status, headers: { 'Content-Type': 'application/json' } }
|
|
279
|
+
else
|
|
280
|
+
message = err?.message or 'Internal Server Error'
|
|
281
|
+
new Response message, { status, headers: { 'Content-Type': 'text/plain' } }
|
|
276
282
|
|
|
277
283
|
# ==============================================================================
|
|
278
284
|
# DSL: Route Registration
|
|
@@ -449,6 +455,23 @@ export session = new Proxy {},
|
|
|
449
455
|
# Env proxy — access env.FOO anywhere (shortcut for process.env)
|
|
450
456
|
export env = new Proxy {}, get: (_, key) -> process.env[key]
|
|
451
457
|
|
|
458
|
+
# ==============================================================================
|
|
459
|
+
# Error Helpers — Halt request with an HTTP error
|
|
460
|
+
# ==============================================================================
|
|
461
|
+
|
|
462
|
+
export error = (message = 'Bad request', status = 400) ->
|
|
463
|
+
throw Object.assign(new Error(message), { status })
|
|
464
|
+
|
|
465
|
+
export notice = (message = 'Something went wrong', status = 400) ->
|
|
466
|
+
throw Object.assign(new Error(message), { status, notice: message })
|
|
467
|
+
|
|
468
|
+
export bail = ->
|
|
469
|
+
store = requestContext.getStore()
|
|
470
|
+
if store?.env?.session?
|
|
471
|
+
for key of store.env.session
|
|
472
|
+
delete store.env.session[key]
|
|
473
|
+
throw Object.assign(new Error('Forbidden'), { status: 403 })
|
|
474
|
+
|
|
452
475
|
# ==============================================================================
|
|
453
476
|
# Utility Functions
|
|
454
477
|
# ==============================================================================
|
|
@@ -607,7 +630,7 @@ export read = (name = null, type = null, miss = null) ->
|
|
|
607
630
|
# missing value helper
|
|
608
631
|
done = (must = false) ->
|
|
609
632
|
return miss() if typeof miss is 'function'
|
|
610
|
-
throw new Error
|
|
633
|
+
throw Object.assign(new Error("Missing required field: #{name}"), { status: 400 }) if must
|
|
611
634
|
return miss ?? null
|
|
612
635
|
|
|
613
636
|
# get value from store
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/server",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10",
|
|
4
4
|
"description": "Pure Rip web framework and application server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "api.rip",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"rip-lang": ">=3.13.
|
|
48
|
+
"rip-lang": ">=3.13.18"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"api.rip",
|