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

Adapters v0 #2855

Merged
merged 19 commits into from
Mar 24, 2022
Merged

Adapters v0 #2855

merged 19 commits into from
Mar 24, 2022

Conversation

matthewp
Copy link
Contributor

Changes

  • This provides initial support for adapters for SSR usage. The first adapter provided via this PR is one that can be used with Node.js generically. Example usage with Express:

astro.config.mjs

import nodejs from '@astrojs/node';

export default {
  integrations: [nodejs()]
}

server.mjs

import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';

const app = express();
app.use(ssrHandler);

app.listen(8080);

Testing

Tests updated, also the examples/ssr example uses this new adapter.

Docs

These are coming in a separate PR.

@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2022

🦋 Changeset detected

Latest commit: 34f64f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) labels Mar 22, 2022
@github-actions github-actions bot added the test label Mar 22, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall! Had a few comments.

Also I'm still considering how I feel about adapter being inside integrations. IMO a top-level adapter: nodejs() option would make it clear that you can only have one adapter. Internally, we can just merge it into the integrations array.

module.mjs Outdated Show resolved Hide resolved
packages/astro/src/integrations/index.ts Show resolved Hide resolved
packages/integrations/node/package.json Outdated Show resolved Hide resolved
packages/integrations/node/package.json Outdated Show resolved Hide resolved
packages/integrations/node/src/server.ts Outdated Show resolved Hide resolved
packages/integrations/node/src/server.ts Outdated Show resolved Hide resolved
packages/integrations/node/src/server.ts Show resolved Hide resolved
@matthewp
Copy link
Contributor Author

Also I'm still considering how I feel about adapter being inside integrations.

I don't have a strong opinion here, other than we kind of need setAdapter anyways because an adapter has some additional properties like renderers do. So if adapter: nodejs() is an AstroIntegration that also has to call setAdapter that seems... kind of odd? Otherwise it would be something like this:

{
  name: string;
  serverEntrypoint: string;
  integration: AstroIntegration;
}

Which is ok and something I played around with, but some other feedback elsewhere made it sound like aligning with the renderer way would be good. Happy to discuss, but these are the tradeoffs in my head.

packages/integrations/node/src/index.ts Outdated Show resolved Hide resolved
packages/integrations/node/src/index.ts Outdated Show resolved Hide resolved
@FredKSchott
Copy link
Member

Copying a comment from Discord that I made before realizing this convo was happening:

Yup, I'll just +1 the idea of an adapter being a special adapter: node() config. Even if we know as implementors that it's just another type of integration, most users will never know that and think of it as a special thing ("I deploy to Netlify, so I set my adapter to netlify()"). I think we want to document it this way, so giving it a special place in the config makes sense as a user story.

@matthewp
Copy link
Contributor Author

@natemoo-re @FredKSchott I updated the PR to accept the adapter through an adapter property like so:

import nodejs from '@astrojs/node';

export default {
  adapter: nodejs()
}

It's still an AstroIntegration though.

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

.changeset/hot-plants-help.md Outdated Show resolved Hide resolved
Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left two small comments

@matthewp matthewp merged commit 5e52814 into main Mar 24, 2022
@matthewp matthewp deleted the adapters-3 branch March 24, 2022 11:26
This was referenced Mar 24, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Adapter v0

* Finalizing adapters

* Update the lockfile

* Add the default adapter after config setup is called

* Create the default adapter in config:done

* Fix lint error

* Remove unused callConfigSetup

* remove unused export

* Use a test adapter to test SSR

* Adds a changeset

* Updated based on feedback

* Updated the lockfile

* Only throw if set to a different adapter

* Clean up outdated comments

* Move the adapter to an  config option

* Make adapter optional

* Update the docs/changeset to reflect config API change

* Clarify regular Node usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants