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

Static and Serverless Hosting Runtime Adapters #1008

Closed
Tracked by #1120
thescientist13 opened this issue Nov 21, 2022 · 5 comments · Fixed by #1120, #1122, #1128 or #1139
Closed
Tracked by #1120

Static and Serverless Hosting Runtime Adapters #1008

thescientist13 opened this issue Nov 21, 2022 · 5 comments · Fixed by #1120, #1122, #1128 or #1139
Assignees
Labels
alpha.1 CLI documentation Greenwood specific docs feature New feature or request RFC Proposal and changes to workflows, architecture, APIs, etc v0.29.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Nov 21, 2022

Overview

Would like to provide Greenwood with the ability to adapt to specific runtimes / platforms for support Serverless and Edge runtimes like:

In particular, supporting #1007 , which will vary per hosting provider. The goal would be to support the following as Serverless and / or Edge functions:

  1. API Routes
  2. SSR Routes (would this need evaluate (remove) use of Workers for SSR and prerendering #1088 )

Details

Main thoughts include

  1. One off page routes (see SSR and Serverless experiments [DO NOT MERGE]  #812)
  2. Being able to work without a filesystem - Agnostic Runtime #953
  3. SSR pages will need access to the request object, no?
  4. Do we need single file bundles (SFBs) for SSR page and API routes #1118 ?
  5. Consolidate and document build out; manifest.json, resources.json, etc as identified in Enhancement/issue 946 decouple build and serve commands from workspace #1079 including a serializable version of the graph and manifest for SSR (as identified in Enhancement/issue 946 decouple build and serve commands from workspace #1079)
  6. better way to "DI" compilation into generated SSR pages instead of through handler in bundle lifecycle? (As identified in Enhancement/issue 946 decouple build and serve commands from workspace #1079) - completed in evaluate (remove) use of Workers for SSR and prerendering #1088
  7. Should API and SSR pages have chunks, or be entirely self contained and also minified in rollup.config.js? (As identified in Enhancement/issue 946 decouple build and serve commands from workspace #1079 ) - deferred to single file bundles (SFBs) for SSR page and API routes #1118
  8. WCC Enhancements
  9. Maybe a guide self hosting for greenwood serve?
  10. Rehydrate graph in memory

In concert with #953

@thescientist13 thescientist13 added RFC Proposal and changes to workflows, architecture, APIs, etc documentation Greenwood specific docs Plugins Greenwood Plugins CLI feature New feature or request labels Nov 21, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Nov 21, 2022
@thescientist13 thescientist13 changed the title Agnostic Runtimes (Adapters) Serverless + Edge (Agnostic Runtime Adapters) Nov 21, 2022
@thescientist13

This comment was marked as outdated.

@thescientist13 thescientist13 changed the title Serverless + Edge (Agnostic Runtime Adapters) Serverless + Edge (Agnostic Runtime Adapters / Strategies) Nov 30, 2022
@thescientist13 thescientist13 changed the title Serverless + Edge (Agnostic Runtime Adapters / Strategies) Serverless + Edge (Platform Adapters / Strategies) Dec 3, 2022
@thescientist13 thescientist13 removed the Plugins Greenwood Plugins label Dec 3, 2022
@thescientist13 thescientist13 self-assigned this Dec 3, 2022
@thescientist13
Copy link
Member Author

thescientist13 commented Jan 2, 2023

So have been doing a little exploration into this with Netlify Serverless functions
AnalogStudiosRI/www.tuesdaystunes.tv#114

Current takeaways are:

  1. Main issue is that import.meta.url is not supported by default, which "breaks" the WCC use case in /api/fragment, but we should hopefully be able to "bundle" this away anyway 🤞
  2. Users will likely need to add / modify their netlify.toml to include a redirect for /api/* routes, e.g.
    [[redirects]]
    from = "/api/*"
    to = "/.netlify/functions/:splat"
    status = 200
  3. For Node 18, will need to manually set the AWS_LAMBDA_JS_RUNTIME environment variable in the UI to nodejs14.x

@thescientist13 thescientist13 pinned this issue Apr 9, 2023
@thescientist13 thescientist13 changed the title Serverless + Edge (Platform Adapters / Strategies) Serverless + Edge (Runtime Adapters / Strategies) May 13, 2023
@thescientist13
Copy link
Member Author

Got an example of Greenwood running on Fly.io
https://github.com/ProjectEvergreen/greenwood-demo-platform-fly

@thescientist13
Copy link
Member Author

Just a heads up Netlify (esbuild specifically) doesn't seem to support import.meta.url :/

Had to do something like this to get it working
https://github.com/ProjectEvergreen/greenwood-demo-adapter-netlify/pulls

await fs.writeFile(outputUrl, `
  import 'wc-compiler/src/dom-shim.js';
  import Page from './_${filename}';

  export async function handler(request) {
    console.log('${JSON.stringify(page)}');          

    let initBody = ${body};
    let initHtml = \`${html}\`;

    if (!initBody) {
      const page = new Page();
      await page.connectedCallback();

      initHtml = initHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, page.innerHTML);
    }

    return new Response(initHtml);
  }
`);

@thescientist13 thescientist13 changed the title Serverless + Edge (Runtime Adapters / Strategies) Serverless + Edge (Runtime Adapters) Strategy Jul 23, 2023
This was linked to pull requests Jul 23, 2023
@thescientist13
Copy link
Member Author

OK, cutting this off at just Serverless (and static) hosting for now, with plugins ready to land for Vercel and Netlify. Created tracking items for the following

@thescientist13 thescientist13 changed the title Serverless + Edge (Runtime Adapters) Strategy Static and Serverless Hosting Runtime Adapters Aug 12, 2023
@thescientist13 thescientist13 unpinned this issue Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment