Skip to content

Commit

Permalink
feat: stormkit preset (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
danielroe and pi0 authored Apr 15, 2022
1 parent 3b00d1d commit 7316385
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/guide/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Built-in presets:
- `node-cli`
- `render-com`
- `service-worker`
- `stormkit`
- `vercel` ([deployment guide](https://v3.nuxtjs.org/guide/deployment/vercel))

You can build nitro project against a specific preset using `NITRO_PRESET=name npx nitropack build`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"serve-placeholder": "^2.0.1",
"serve-static": "^1.15.0",
"source-map-support": "^0.5.21",
"std-env": "^3.0.1",
"std-env": "^3.1.0",
"table": "^6.8.0",
"ufo": "^0.8.3",
"unenv": "^0.4.6",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export * from './node-server'
export * from './node'
export * from './render-com'
export * from './service-worker'
export * from './stormkit'
export * from './vercel'
9 changes: 9 additions & 0 deletions src/presets/stormkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineNitroPreset } from '../preset'

export const stormkit = defineNitroPreset({
entry: '#nitro/entries/stormkit',
externals: true,
output: {
dir: '{{ rootDir }}/.stormkit'
}
})
29 changes: 29 additions & 0 deletions src/runtime/entries/stormkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { ALBHandler } from 'aws-lambda'
import '#nitro/virtual/polyfill'
import { withQuery } from 'ufo'
import { nitroApp } from '../app'

export const handler: ALBHandler = async function handler (event, context) {
const url = withQuery(event.path, event.queryStringParameters || {})
const method = event.httpMethod || 'get'

const r = await nitroApp.localCall({
event,
url,
context,
headers: event.headers,
method,
query: event.queryStringParameters,
body: event.body
})

return {
statusCode: r.status,
headers: normalizeOutgoingHeaders(r.headers),
body: r.body.toString()
}
}

function normalizeOutgoingHeaders (headers: Record<string, string | string[] | undefined>) {
return Object.fromEntries(Object.entries(headers).map(([k, v]) => [k, Array.isArray(v) ? v.join(',') : v!]))
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function replaceAll (input: string, from: string, to: string) {
const autodetectableProviders = {
azure_static: 'azure',
netlify: 'netlify',
stormkit: 'stormkit',
vercel: 'vercel'
}

Expand Down

0 comments on commit 7316385

Please sign in to comment.