expose request in ribbit
This commit is contained in:
parent
68cd61227b
commit
0556efb41f
|
|
@ -53,6 +53,15 @@ for (const name of HTML5_TAGS) {
|
|||
; (ribbitGlobals as any)[name].tagName = name
|
||||
}
|
||||
|
||||
const tag = async (tagName: string, atNamed = {}, ...args: any[]) => {
|
||||
if (typeof args[0] === 'function')
|
||||
await tagBlock(tagName, atNamed, args[0])
|
||||
else
|
||||
tagCall(tagName, atNamed, ...args)
|
||||
|
||||
return TAG_TOKEN
|
||||
}
|
||||
|
||||
const tagBlock = async (tagName: string, props = {}, fn: Function) => {
|
||||
const attrs = Object.entries(props).map(([key, value]) => `${key}="${value}"`)
|
||||
const space = attrs.length ? ' ' : ''
|
||||
|
|
@ -78,12 +87,3 @@ const tagCall = (tagName: string, atNamed = {}, ...args: any[]) => {
|
|||
else
|
||||
buffer.push(`<${tagName}${space}${attrs.join(' ')}>${children}</${tagName}>`)
|
||||
}
|
||||
|
||||
const tag = async (tagName: string, atNamed = {}, ...args: any[]) => {
|
||||
if (typeof args[0] === 'function')
|
||||
await tagBlock(tagName, atNamed, args[0])
|
||||
else
|
||||
tagCall(tagName, atNamed, ...args)
|
||||
|
||||
return TAG_TOKEN
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export function startWeb(rootPath: string) {
|
|||
if (page === 'layout') return c.text('404 Not Found', 404)
|
||||
|
||||
const params = c.req.query()
|
||||
const request = { method: c.req.method }
|
||||
if (c.req.method === 'POST') {
|
||||
const formData = await c.req.formData()
|
||||
for (const [key, value] of formData.entries()) {
|
||||
|
|
@ -39,7 +40,7 @@ export function startWeb(rootPath: string) {
|
|||
const layoutFile = Bun.file(layoutPath)
|
||||
let layoutCode = await layoutFile.exists() ? await layoutFile.text() : ''
|
||||
|
||||
const vm = new Shrimp(Object.assign({}, ribbitGlobals, { params }))
|
||||
const vm = new Shrimp(Object.assign({}, ribbitGlobals, { params, request }))
|
||||
|
||||
if (await file.exists()) {
|
||||
let content = ''
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user