You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to make SSR work for lambda@edge. With the aws-lambda preset, it mostly works (the Lambda gets invoked and produces a response via the router), but there are quirks. (And yes, I did notice where it emits the warning: The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.) But, I'm hoping I can solve the "last mile".
CloudFront expects the response's headers to have a particular shape. I'm confident all the needed information is available, if only I can hook into the Nitro response. I'm having some trouble doing that, and I wonder
is my approach to solving the problem (transform response via Nitro afterResponse hook after routing & TSR render) doable?
is it reasonable to solve the problem that way? Or, is another approach going to be recommended?
For now, I just want to put something into the logs to see that my plugin ran and hooked Nitro as desired.
nitro-plugins/lambda_edge.ts
import { defineNitroPlugin } from 'nitropack/runtime';
export default defineNitroPlugin((nitroApp) => {
type Event = Parameters<Parameters<typeof nitroApp.hooks.hook>[1]>[0];
type Response = Parameters<Parameters<typeof nitroApp.hooks.hook>[1]>[1];
nitroApp.hooks.hook("afterResponse", (event: Event, response: Response) => {
console.log("on after response", event.path, { body: response?.body });
});
});
With the above, I'm seeing a build-time error:
~/Projects/Swiftly-Sparking-Salamander/react-frontend/ [tommy/tsstart+*] pnpm run build
> tanstack-start-example-counter@ build /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend
> vinxi build
vinxi v0.5.1
The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.
⚙ Building your app...
removing /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend/.vinxi/build/client
removing /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend/.vinxi/build/ssr
removing /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend/.vinxi/build/server
vinxi v0.5.1
The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.
⚙ Building your router client...
📦 Compiling client router...
vinxi building router client in client mode
♻️ Generating routes...
✅ Processed route in 72ms
vite v6.0.11 building for production...
virtual:$vinxi/handler/client (1:151): "default" is not exported by "app/client.tsx", imported by "virtual:$vinxi/handler/client".
✓ 116 modules transformed.
.vinxi/build/client/_build/.vite/manifest.json 0.66 kB │ gzip: 0.24 kB
.vinxi/build/client/_build/assets/client-CYINlULw.js 0.06 kB │ gzip: 0.08 kB
.vinxi/build/client/_build/assets/index-DnfUxv5i.js 4.73 kB │ gzip: 1.95 kB
.vinxi/build/client/_build/assets/client-Dg69imtP.js 212.94 kB │ gzip: 69.50 kB
✓ built in 533ms
✔ build done 6:00:29 PM
⚙ Built your router client successfully
vinxi v0.5.1
The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.
⚙ Building your router ssr...
📦 Compiling ssr router...
vinxi building router ssr in http mode
vite v6.0.11 building SSR bundle for production...
"H3Error", "MIMES", "callNodeListener", "createApp", "createAppEventHandler", "createError", "createEvent", "createRouter", "defineEventHandler", "defineLazyEventHandler", "defineNodeListener", "defineNodeMiddleware", "defineRequestMiddleware", "defineResponseMiddleware", "defineWebSocket", "dynamicEventHandler", "fromNodeMiddleware", "fromPlainHandler", "fromWebHandler", "isCorsOriginAllowed", "isError", "isEventHandler", "isStream", "isWebResponse", "lazyEventHandler", "promisifyNodeListener", "sanitizeStatusCode", "sanitizeStatusMessage", "serveStatic", "splitCookiesString", "toEventHandler", "toNodeListener", "toPlainHandler" and "toWebHandler" are imported from external module "h3" but never used in "node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_react-d_vacyvckw7jnc4osk7okirjb5xa/node_modules/@tanstack/start-server/dist/esm/createStartHandler.js" and "node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_react-d_vacyvckw7jnc4osk7okirjb5xa/node_modules/@tanstack/start-server/dist/esm/index.js".
✓ 49 modules transformed.
.vinxi/build/ssr/.vite/manifest.json 0.61 kB
.vinxi/build/ssr/ssr.js 0.22 kB
.vinxi/build/ssr/assets/index-BAIi-Ra6.js 4.91 kB
.vinxi/build/ssr/assets/ssr-CpPS3q6A.js 17.69 kB
✓ built in 200ms
✔ build done 6:00:30 PM
⚙ Built your router ssr successfully
vinxi v0.5.1
The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.
⚙ Building your router server...
📦 Compiling server router...
vinxi building router server in http mode
vite v6.0.11 building SSR bundle for production...
"H3Error", "MIMES", "callNodeListener", "createApp", "createAppEventHandler", "createError", "createEvent", "createRouter", "defineEventHandler", "defineLazyEventHandler", "defineNodeListener", "defineNodeMiddleware", "defineRequestMiddleware", "defineResponseMiddleware", "defineWebSocket", "dynamicEventHandler", "fromNodeMiddleware", "fromPlainHandler", "fromWebHandler", "isCorsOriginAllowed", "isError", "isEventHandler", "isStream", "isWebResponse", "lazyEventHandler", "promisifyNodeListener", "sanitizeStatusCode", "sanitizeStatusMessage", "serveStatic", "splitCookiesString", "toEventHandler", "toNodeListener", "toPlainHandler" and "toWebHandler" are imported from external module "h3" but never used in "node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_react-d_vacyvckw7jnc4osk7okirjb5xa/node_modules/@tanstack/start-server/dist/esm/createStartHandler.js" and "node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_react-d_vacyvckw7jnc4osk7okirjb5xa/node_modules/@tanstack/start-server/dist/esm/index.js".
✓ 40 modules transformed.
.vinxi/build/server/_server/.vite/manifest.json 0.75 kB
.vinxi/build/server/_server/server.js 0.13 kB
.vinxi/build/server/_server/assets/index-CLumUnQg.js 3.87 kB
.vinxi/build/server/_server/assets/server-Ds_sJbQW.js 4.90 kB
✓ built in 173ms
✔ build done 6:00:31 PM
⚙ Built your router server successfully
ERROR Cannot find module 'nitro-plugins/lambda_edge.ts' 6:00:31 PM
Require stack:
- /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/lib/build.js
Require stack:
- node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/lib/build.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
at Function.resolve (node:internal/modules/helpers:190:19)
at node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/lib/build.js:139:16
at Array.map (<anonymous>)
at createBuild (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/lib/build.js:134:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.run (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/bin/cli.mjs:235:5)
at async runCommand (node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:316:16)
at async runCommand (node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:307:11)
at async runMain (node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:445:7)
ERROR Cannot find module 'nitro-plugins/lambda_edge.ts' 6:00:31 PM
Require stack:
- /Users/sh4m1l65/Projects/Swiftly-Sparking-Salamander/react-frontend/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/vinxi/lib/build.js
ELIFECYCLE Command failed with exit code 1.
~/Projects/Swiftly-Sparking-Salamander/react-frontend/ [tommy/tsstart+*]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to make SSR work for lambda@edge. With the
aws-lambda
preset, it mostly works (the Lambda gets invoked and produces a response via the router), but there are quirks. (And yes, I did notice where it emits the warning: The deployment preset 'aws-lambda' is not fully supported yet and may not work as expected.) But, I'm hoping I can solve the "last mile".CloudFront expects the response's headers to have a particular shape. I'm confident all the needed information is available, if only I can hook into the Nitro response. I'm having some trouble doing that, and I wonder
I started with the start-counter example, then modified:
app.config.js:
For now, I just want to put something into the logs to see that my plugin ran and hooked Nitro as desired.
nitro-plugins/lambda_edge.ts
With the above, I'm seeing a build-time error:
Beta Was this translation helpful? Give feedback.
All reactions