@stacksjs/router 0.65.0 → 0.66.0
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/dist/index.js +77 -65
- package/dist/index.js.map +216 -62
- package/package.json +11 -11
- package/src/router.ts +5 -3
- package/src/server.ts +20 -19
- package/src/utils.ts +0 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.66.0",
|
|
5
5
|
"description": "The Stacks framework router.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
|
|
@@ -37,19 +37,19 @@
|
|
|
37
37
|
"prepublishOnly": "bun run build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stacksjs/actions": "0.
|
|
41
|
-
"@stacksjs/config": "0.
|
|
42
|
-
"@stacksjs/error-handling": "0.
|
|
43
|
-
"@stacksjs/logging": "0.
|
|
44
|
-
"@stacksjs/orm": "0.
|
|
45
|
-
"@stacksjs/path": "0.
|
|
46
|
-
"@stacksjs/storage": "0.
|
|
47
|
-
"@stacksjs/validation": "0.
|
|
40
|
+
"@stacksjs/actions": "0.65.1",
|
|
41
|
+
"@stacksjs/config": "0.65.1",
|
|
42
|
+
"@stacksjs/error-handling": "0.65.1",
|
|
43
|
+
"@stacksjs/logging": "0.65.1",
|
|
44
|
+
"@stacksjs/orm": "0.65.1",
|
|
45
|
+
"@stacksjs/path": "0.65.1",
|
|
46
|
+
"@stacksjs/storage": "0.65.1",
|
|
47
|
+
"@stacksjs/validation": "0.65.1",
|
|
48
48
|
"unplugin-vue-router": "^0.10.8",
|
|
49
49
|
"vue-router": "^4.4.5"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@stacksjs/development": "0.
|
|
53
|
-
"@stacksjs/types": "0.
|
|
52
|
+
"@stacksjs/development": "0.65.1",
|
|
53
|
+
"@stacksjs/types": "0.65.1"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/router.ts
CHANGED
|
@@ -321,11 +321,13 @@ export class Router implements RouterInterface {
|
|
|
321
321
|
return await actionModule.default.handle(requestInstance)
|
|
322
322
|
}
|
|
323
323
|
catch (error: any) {
|
|
324
|
-
|
|
324
|
+
if (error.status === 422)
|
|
325
|
+
return { status: 422, errors: JSON.parse(error.message) }
|
|
326
|
+
|
|
325
327
|
if (!error.status)
|
|
326
|
-
return { status: 500, errors: error }
|
|
328
|
+
return { status: 500, errors: error.message }
|
|
327
329
|
|
|
328
|
-
return { status: error.status, errors: error }
|
|
330
|
+
return { status: error.status, errors: error.message }
|
|
329
331
|
}
|
|
330
332
|
}
|
|
331
333
|
|
package/src/server.ts
CHANGED
|
@@ -137,15 +137,6 @@ type CallbackWithStatus = Route['callback'] & { status: number }
|
|
|
137
137
|
async function execute(foundRoute: Route, req: Request, { statusCode }: Options) {
|
|
138
138
|
const foundCallback: CallbackWithStatus = await route.resolveCallback(foundRoute.callback)
|
|
139
139
|
|
|
140
|
-
// return new Response(`<html><body><h1>Error</h1><p>${foundCallback}</p><pre></pre></body></html>`, {
|
|
141
|
-
// headers: {
|
|
142
|
-
// 'Content-Type': 'text/html',
|
|
143
|
-
// 'Access-Control-Allow-Origin': '*',
|
|
144
|
-
// 'Access-Control-Allow-Headers': '*',
|
|
145
|
-
// },
|
|
146
|
-
// status: 500,
|
|
147
|
-
// })
|
|
148
|
-
|
|
149
140
|
const middlewarePayload = await executeMiddleware(foundRoute)
|
|
150
141
|
|
|
151
142
|
if (
|
|
@@ -264,6 +255,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
|
|
|
264
255
|
const { status, ...rest } = await foundCallback
|
|
265
256
|
|
|
266
257
|
const { errors } = rest
|
|
258
|
+
|
|
267
259
|
return new Response(JSON.stringify(errors), {
|
|
268
260
|
headers: {
|
|
269
261
|
'Content-Type': 'application/json',
|
|
@@ -276,8 +268,8 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
|
|
|
276
268
|
|
|
277
269
|
if (foundCallback.status === 403) {
|
|
278
270
|
const { status, ...rest } = await foundCallback
|
|
279
|
-
|
|
280
|
-
return new Response(JSON.stringify(
|
|
271
|
+
const { errors } = rest
|
|
272
|
+
return new Response(JSON.stringify(errors), {
|
|
281
273
|
headers: {
|
|
282
274
|
'Content-Type': 'application/json',
|
|
283
275
|
'Access-Control-Allow-Origin': '*',
|
|
@@ -290,7 +282,8 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
|
|
|
290
282
|
if (foundCallback.status === 422) {
|
|
291
283
|
const { status, ...rest } = await foundCallback
|
|
292
284
|
|
|
293
|
-
|
|
285
|
+
const { errors } = rest
|
|
286
|
+
return new Response(JSON.stringify(errors), {
|
|
294
287
|
headers: {
|
|
295
288
|
'Content-Type': 'application/json',
|
|
296
289
|
'Access-Control-Allow-Origin': '*',
|
|
@@ -304,13 +297,21 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
|
|
|
304
297
|
const { status, ...rest } = await foundCallback
|
|
305
298
|
|
|
306
299
|
const { errors } = rest
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
},
|
|
313
|
-
|
|
300
|
+
|
|
301
|
+
const file = Bun.file(path.corePath('error-handling/src/views/500.html'))
|
|
302
|
+
|
|
303
|
+
return file.text().then((htmlContent) => {
|
|
304
|
+
// Replace the placeholder with the actual error message
|
|
305
|
+
const modifiedHtml = htmlContent.replace('{{ERROR_MESSAGE}}', errors)
|
|
306
|
+
|
|
307
|
+
return new Response(modifiedHtml, {
|
|
308
|
+
headers: {
|
|
309
|
+
'Content-Type': 'text/html',
|
|
310
|
+
'Access-Control-Allow-Origin': '*',
|
|
311
|
+
'Access-Control-Allow-Headers': '*',
|
|
312
|
+
},
|
|
313
|
+
status: 500,
|
|
314
|
+
})
|
|
314
315
|
})
|
|
315
316
|
}
|
|
316
317
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ModelRequest, RequestInstance } from '@stacksjs/types'
|
|
2
2
|
import { type Ok, ok } from '@stacksjs/error-handling'
|
|
3
3
|
import { path } from '@stacksjs/path'
|
|
4
|
-
import { existsSync } from '@stacksjs/storage'
|
|
5
4
|
import { camelCase } from '@stacksjs/strings'
|
|
6
5
|
import { route } from './router'
|
|
7
6
|
|
|
@@ -75,7 +74,6 @@ export async function extractModelRequest(action: string): Promise<RequestInstan
|
|
|
75
74
|
export async function findRequestInstance(requestInstance: string): Promise<ModelRequest> {
|
|
76
75
|
const frameworkDirectory = path.storagePath('framework/requests')
|
|
77
76
|
const filePath = path.join(frameworkDirectory, `${requestInstance}.ts`)
|
|
78
|
-
const pathExists = await existsSync(filePath)
|
|
79
77
|
|
|
80
78
|
const reqInstance = await import(filePath)
|
|
81
79
|
|