2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-07-15 09:38:06 +00:00
|
|
|
import { setupTest, testNitroBehavior, importModule } from './_tests.mjs'
|
2021-04-23 19:52:32 +00:00
|
|
|
|
|
|
|
describe('nitro:preset:lambda', () => {
|
2021-07-15 09:38:06 +00:00
|
|
|
const ctx = setupTest('lambda')
|
2021-04-23 19:52:32 +00:00
|
|
|
testNitroBehavior(ctx, async () => {
|
2021-07-15 09:38:06 +00:00
|
|
|
const { handler } = await importModule(resolve(ctx.outDir, 'server/index.mjs'))
|
2021-04-23 19:52:32 +00:00
|
|
|
return async ({ url: rawRelativeUrl, headers, method, body }) => {
|
|
|
|
// creating new URL object to parse query easier
|
|
|
|
const url = new URL(`https://example.com${rawRelativeUrl}`)
|
|
|
|
const queryStringParameters = Object.fromEntries(url.searchParams.entries())
|
|
|
|
const event = {
|
|
|
|
path: url.pathname,
|
|
|
|
headers: headers || {},
|
|
|
|
method: method || 'GET',
|
|
|
|
queryStringParameters,
|
|
|
|
body: body || ''
|
|
|
|
}
|
|
|
|
const res = await handler(event)
|
|
|
|
return {
|
|
|
|
data: res.body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|