Prathmesh010190 opened a new pull request, #203: URL: https://github.com/apache/openserverless/pull/203
Adds a SvelteKit adapter that builds an app as an Apache OpenServerless web action, following the same adapt() structure as @sveltejs/adapter-node. Bridges OpenServerless's web-action invocation protocol (__ow_method/__ow_headers/__ow_path/__ow_query/__ow_body) to/from a Web standard Request/Response via SvelteKit's platform-agnostic Server. Verified locally: built against a real scaffolded SvelteKit app and invoked the built action directly with simulated OpenServerless params, confirming correct SSR output, status code, and headers. <!-- Please make sure you have read and understood the contributing guidelines --> - [x] I have registered the PR [[changes](https://claude.ai/changes)](../changes). ### Ⅰ. Describe what this PR did Adds `svelte-adapter-openserverless`, a new SvelteKit adapter package at `adapters/svelte-adapter-openserverless`, so a SvelteKit app can be built and deployed as an OpenServerless web action — the same way SvelteKit already supports Vercel and Netlify via their respective adapters. It consists of: - `index.js` — the adapter itself, following `@sveltejs/adapter-node`'s `adapt()` flow (write client assets, write server, generate manifest), plus optional emission of an `ops` action manifest (`packages/<name>.yaml`) so `ops project deploy` can pick up the built action automatically. - `src/handler.js` — translates OpenServerless's web-action invocation shape (`__ow_method`, `__ow_headers`, `__ow_path`, `__ow_query`, `__ow_body`) into a Web standard `Request`, runs it through SvelteKit's platform-agnostic `Server`, and converts the resulting `Response` back into the `{ statusCode, headers, body }` shape OpenServerless expects, including base64 handling for binary payloads. - `index.d.ts` — typed adapter options. - `README.md` — usage, build output layout, and deploy instructions. - `test/protocol.test.js` — unit tests for the binary-detection helper. ### Ⅱ. Does this pull request fix one issue? fixes #149 ### Ⅲ. Why don't you add test cases (unit test/integration test)? Unit tests are included (`test/protocol.test.js`, passing — see verification below) for the pure helper logic. Full integration testing of `src/handler.js` requires a completed SvelteKit build (it imports the generated `../server/index.js` and `../server/manifest.js`), so instead of mocking that, I verified it against a real build: - Scaffolded a fresh SvelteKit app (`npx sv create`, minimal template) and configured it to use this adapter. - Ran `npm run build` and confirmed the adapter runs (not falling back to `adapter-auto`) and produces the expected `build/` layout and `packages/web.yaml`. - Directly invoked the built `build/action.js`'s exported `main()` with a simulated OpenServerless web-action params object (`__ow_method: 'get'`, `__ow_headers`, `__ow_path`, `__ow_query: 'name=OpenServerless'`). - Confirmed: `statusCode: 200`, correct headers (`content-type: text/html`, `x-sveltekit-page: true`), and full SSR HTML output with the server-side `load()` data correctly reflecting the query string in the rendered response. Not yet done: an actual deploy to a live `ops`/OpenServerless cluster, since I don't have access to one. Happy to have a maintainer or CI validate that step before merge. ### Ⅳ. Describe how to verify it 1. `cd adapters/svelte-adapter-openserverless && npm install && npm test` — unit tests should pass. 2. Scaffold a test SvelteKit app elsewhere (`npx sv create demo-app`), install this adapter (`npm install <path-to-this-folder>`), and point `vite.config.js`'s `sveltekit({ adapter: ... })` (or `svelte.config.js`, depending on SvelteKit/CLI version) at `svelte-adapter-openserverless`. 3. `npm run build` — should print `Using svelte-adapter-openserverless` and the deploy hint, and produce `build/action.js`, `build/server/`, `build/client/`, and `packages/<name>.yaml`. 4. Optionally invoke it directly with Node to confirm SSR works without a live cluster: ```js import { main } from './build/action.js'; const result = await main({ __ow_method: 'get', __ow_headers: { host: 'localhost:3000' }, __ow_path: '/', __ow_query: '' }); console.log(result.statusCode, result.body); ``` 5. For a real deployment: `ops action update web/sveltekit-app build/action.js --kind nodejs:20 --web true --main main`, then invoke via `ops action invoke web/sveltekit-app --web`. ### Ⅴ. Special notes for reviews A few open questions I'd appreciate maintainer input on before this is considered final: 1. **Binary detection** — request/response body binary detection currently relies on inferring from the `Content-Type` header. If the OpenServerless Node runtime exposes an explicit flag on inbound params (e.g. `__ow_isBase64Encoded`), I'd prefer to key off that instead — I couldn't find it documented. 2. **Package location** — I've placed this at `adapters/svelte-adapter-openserverless` inside the main repo. Since `apache/openserverless` is otherwise composed entirely of git submodules for actual code, let me know if you'd rather this live in its own repository instead. 3. **Static assets** — the adapter currently just writes `build/client` to disk and leaves hosting/upload to `ops project deploy`. Let me know if the adapter should do more here. 4. Only validated against `nodejs:20` and via local invocation (see above) — no live cluster deploy yet. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
