Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stormkit preset #103

Merged
merged 6 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guide/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Built-in presets:
- `node-server` ([deployment guide](https://v3.nuxtjs.org/guide/deployment/presets/server))
- `node-cli`
- `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 @@ -100,7 +100,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 @@ -11,4 +11,5 @@ export * from './node-cli'
export * from './node-server'
export * from './node'
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