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: Move hooks.{js|ts} init to Server.init instead of Server.respond #6179

Merged
merged 22 commits into from
Aug 24, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fa53fbb
feat: Move hooks.js initialization into Server.init
elliott-with-the-longest-name-on-github Aug 23, 2022
02c5764
fix: Server type
elliott-with-the-longest-name-on-github Aug 23, 2022
3bfd40c
feat: Await Server.init in adapters
elliott-with-the-longest-name-on-github Aug 23, 2022
286648a
feat: Await server.init in preview
elliott-with-the-longest-name-on-github Aug 23, 2022
204acb1
fix: Init server during prerender
elliott-with-the-longest-name-on-github Aug 23, 2022
16cdc7b
feat: Init hooks when dev mode starts instead of on first request
elliott-with-the-longest-name-on-github Aug 23, 2022
f8bd413
fix: Prerendering, but better
elliott-with-the-longest-name-on-github Aug 23, 2022
ea9c218
feat: Test env vars in prerender
elliott-with-the-longest-name-on-github Aug 23, 2022
c6a7f6d
fix: Remove console.log
elliott-with-the-longest-name-on-github Aug 23, 2022
7f31360
fix: Import in hooks.js of basics test app
elliott-with-the-longest-name-on-github Aug 23, 2022
3fba16e
changeset
elliott-with-the-longest-name-on-github Aug 23, 2022
2c7e2a8
Update packages/adapter-netlify/src/serverless.js
elliott-with-the-longest-name-on-github Aug 23, 2022
9583fbc
Update packages/kit/src/vite/build/build_server.js
elliott-with-the-longest-name-on-github Aug 23, 2022
6cb779c
feat: Enable top-level await in `adapter-node`
elliott-with-the-longest-name-on-github Aug 23, 2022
8ef2f83
feat: Add warning comment for future devs
elliott-with-the-longest-name-on-github Aug 23, 2022
7afab3e
fix: Init env prior to hooks
elliott-with-the-longest-name-on-github Aug 23, 2022
6131dd3
Merge branch '6147/sejohnson-move-hooks-init' of github.com:sveltejs/…
elliott-with-the-longest-name-on-github Aug 23, 2022
a8c62b2
fix: Remove dear Rich
elliott-with-the-longest-name-on-github Aug 23, 2022
23a9206
Merge branch 'master' into 6147/sejohnson-move-hooks-init
elliott-with-the-longest-name-on-github Aug 23, 2022
580ffd2
fix: Apparently didn't like my tsconfig
elliott-with-the-longest-name-on-github Aug 23, 2022
e9286ad
fix: Move env and hooks initialization later
elliott-with-the-longest-name-on-github Aug 23, 2022
5b9b0db
move user_hooks init back from whence it came
Rich-Harris Aug 24, 2022
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
Next Next commit
feat: Move hooks.js initialization into Server.init
  • Loading branch information
commit fa53fbb01795926d1bda19c73539851e2e8b1dd4
16 changes: 8 additions & 8 deletions packages/kit/src/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Server {
};
}

init({ env }) {
async init({ env }) {
const entries = Object.entries(env);

const prv = Object.fromEntries(entries.filter(([k]) => !k.startsWith('${
Expand All @@ -99,21 +99,21 @@ export class Server {
set_public_env(pub);

this.options.public_env = pub;
}

async respond(request, options = {}) {
if (!(request instanceof Request)) {
throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
}

if (!this.options.hooks) {
if (!this.options.hooks) {
elliott-with-the-longest-name-on-github marked this conversation as resolved.
Show resolved Hide resolved
const module = await import(${s(hooks)});
this.options.hooks = {
handle: module.handle || (({ event, resolve }) => resolve(event)),
handleError: module.handleError || (({ error }) => console.error(error.stack)),
externalFetch: module.externalFetch || fetch
};
}
}

async respond(request, options = {}) {
if (!(request instanceof Request)) {
throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
}

return respond(request, this.options, options);
}
Expand Down