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(og-gen): Implement middleware and hooks #10469

Merged
merged 58 commits into from
Apr 26, 2024
Merged

Conversation

dac09
Copy link
Collaborator

@dac09 dac09 commented Apr 16, 2024

The OG Gen saga continues with @cannikin and @dac09 ⚔️

This PR adds OgImageMiddleware and Hooks to @redwoodjs/og-gen.

This PR:

  • adds OgImageMiddleware and Hooks to @redwoodjs/og-gen, complete with tests

⚠️ Template changes:

  • updates entry.client template to pass in Routes to App
  • updates App to take children (i.e. Routes)

This is so that we can pass the OG component to be rendered with your App's CSS setup.
I've also coordinated with Tobbe on these changes so we don't need to change things again for server router.

How to use this?

  1. Registering the middleware:

    import OgImageMiddleware from '@redwoodjs/ogimage-gen/middleware'
    
    export const registerMiddleware = () => {
      const ogMw = new OgImageMiddleware({
        App,
        Document,
      })
    
      return [ogMw]
    }
  2. Configure your vite.config.ts

    import vitePluginOgImageGen from '@redwoodjs/ogimage-gen/plugin'
    
    const viteConfig: UserConfig = {
      // 👇 so it builds your OG components
      plugins: [redwood(), vitePluginOgImageGen()],
    }
    
    export default defineConfig(viteConfig)
  3. Add your OG Image component next to the page it's for
    e.g. web/src/pages/AboutPage/AboutPage.png.tsx

  4. Use hooks on AboutPage to generate the ogURL

Tasks:

  • Can we write unit tests for OgImageMiddleware?
  • I haven't tried the hooks yet! RC maybe try out on your project?
  • Move hooks from Rob's project to this PR
  • Figure out ESM/CJS issue we're seeing
  • Find those pesky edge cases e.g. multiple .png.jsx files in a page folder
    - [ ] Can we support image src imports? Not strictly necessary.
    Known limitation. You have to put images in the public folder. We can improve later
    - [ ] DOCS
    We decided to make it a blog post instead, since this is under experimental still

dac09 and others added 22 commits April 10, 2024 16:36
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  feat(og-gen): Adds package and vite plugin for dynamic og generation (#10439)
  chore(deps): bump browserify-sign from 4.2.1 to 4.2.3 (#10446)
  chore(deps): bump tar from 6.1.11 to 6.2.1 in /docs (#10438)
  chore(deps): update dependency firebase to v10.11.0 (#10366)
  fix(auth): Handle when authorization header is lowercased (#10442)
  Update rbac.md - code match (#10405)
  chore: make crwa e2e test work across branches (#10437)
  feat: [Auth] Common AuthProvider & use* changes for middleware auth (#10420)
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  feat(og-gen): Update implementation of useLocation | Update App template (#10441)
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  chore(dbauth-mw): Refactor web side dbAuth creation (#10460)
  chore(router): Prevent circular dependency for namedRoutes (#10463)
  chore(router): route-validators: Better types and clean up comments (#10462)
  feat(server-auth): dbAuth 3/3 -  handle login, logout, signup, etc. requests if forwarded from middleware (#10457)
  docs(router): Document new NavLink className replacement behavior (#10401)
  chore(refactor): Split the router out into smaller logical units (#10434)
  feat(server-auth): Part 1/3: dbAuth middleware support (web side changes) (#10444)
  chore(auth): Build: Put ESM at the root, and CJS in /cjs (#10458)
  fix(ssr): Successfully serve static assets like `favicon.png` (#10455)
  chore(deps): update chore (#10367)
  (docs) Fix useCache headers and links (#10451)
  chore: remove aws-lambda (#10450)
  chore(deps): update dependency typescript to v5.4.5 (#10452)
…d into feat/dc-rc-og-gen-mw-p2

* 'feat/dc-rc-og-gen-mw-p2' of github.com:redwoodjs/redwood:
  set type=module and build for both esm and cjs
@dac09 dac09 added the release:feature This PR introduces a new feature label Apr 16, 2024
@dac09 dac09 added this to the SSR milestone Apr 16, 2024
@dac09 dac09 requested a review from cannikin April 16, 2024 16:10
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  feat(server-auth): WebAuthN support during SSR (#10498)
  Removes old HTML comments from CLI commands doc
  feat(cookieJar): Change cookie.get to directly return value (#10493)
@dac09
Copy link
Collaborator Author

dac09 commented Apr 23, 2024

FINALLY. All checks ✅

Will wait for docs @cannikin, but not sure if we're putting it in this PR. Will leave to you for merge.

@Tobbe any nits by chance? Could you please update your review?

Copy link
Member

Tobbe commented Apr 23, 2024

I’ll have a look

@Tobbe Tobbe changed the title feat(og-gen): Implement middlware and hooks feat(og-gen): Implement middleware and hooks Apr 26, 2024
.changesets/10469.md Outdated Show resolved Hide resolved
.changesets/10469.md Outdated Show resolved Hide resolved
dac09 and others added 2 commits April 26, 2024 20:20
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  RSC: Add RSC+SSR smoke test to CI (#10477)
  fix(dbauth-mw): Use response passed in to middleware (#10516)
  Add redwood.toml to `yarn rw info` (#10518)
  chore(tests): Fix packages/web tests (#10517)
  fix(dbauth-mw): Unset cookie instead of clearing (#10502)
  chore(deps): Upgrade to React canary 20240424 (#10513)
  chore(deps): Upgrade to React Testing Library 14.3.1 (#10514)
  feat(upgrade): Use GitHub token if available when downloading patches (#10515)
@dac09 dac09 enabled auto-merge (squash) April 26, 2024 13:41
@cannikin
Copy link
Member

I built an app from scratch using this branch and everything worked great! I manually made the changes to entry.server.js and vite.config.js but @Josh-Walker-GM has a PR that adds CLI commands to modify them automatically: #10485

@dac09 dac09 merged commit e5f32b6 into main Apr 26, 2024
46 checks passed
@dac09 dac09 deleted the feat/dc-rc-og-gen-mw-p2 branch April 26, 2024 15:40
@cannikin
Copy link
Member

No official docs for the real site yet, but we'll have an announcement blog post that walks through the whole thing. I think when we get closer to SSR being promoted from experimental to feature flag I can write an official reference doc for it.

dac09 added a commit to dac09/redwood that referenced this pull request May 1, 2024
…e-middleware-client

* 'main' of github.com:redwoodjs/redwood:
  chore(server-auth): Automagic middleware auth on supported providers (dbAuth so far) (redwoodjs#10529)
  feat(baremetal): Add more details to error messages (redwoodjs#10527)
  feat(baremetal): Add verbose output to ssh exec (redwoodjs#10525)
  Fix typos in seo-head (`<Metadata />`) docs (redwoodjs#10526)
  chore(cli): Wrap NodeSSH to make sshExec an instance method (redwoodjs#10524)
  Fix broken Azure / MSAL documentation links (redwoodjs#10505)
  chore(deps): Stop using PR build of rehackt - use proper version (redwoodjs#10523)
  feat(og-gen): Implement middleware and hooks (redwoodjs#10469)
  RSC: Rename RSC CI test case (redwoodjs#10521)
  feat(eslint): Disable restricted $api imports for entryserver (redwoodjs#10520)
  RSC: Add RSC+SSR smoke test to CI (redwoodjs#10477)
  fix(dbauth-mw): Use response passed in to middleware (redwoodjs#10516)
@Josh-Walker-GM Josh-Walker-GM modified the milestones: SSR, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants