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

docs: update og generation code with local assets #64888

Merged
merged 5 commits into from
Apr 23, 2024

Conversation

KagamiChan
Copy link
Contributor

@KagamiChan KagamiChan commented Apr 22, 2024

What?

This PR fixes OpenGraph generation code with local assets in Node.js runtime. Also adds some notes on file location.

The updated code is validated with my project on vercel.

Why?

I tried loading a file in public folder(say ./public/og.png). The Node.js local assets example code did work locally with next start but failed with error message Error: ENOENT: no such file or directory when deployed to vercel.

Then I found out the trick here is the relative path. On my local machine the CWD is the root folder so the relative path works, And it seems the CWD is somewhat different on vercel runtime. Then I tried using process.cwd() to get the CWD and construct a absolute path, this has been validated with my project on vercel.

Also it's worthy to note where the local assets should be placed, so that devs could be less confused.

I tried loading a file in `public` folder(say `./public/og.png`). The Node.js local assets example code did work locally with `next start` but failed with error message `Error: ENOENT: no such file or directory` when deployed to vercel. 

Then I found out the trick here is the relative path here. On my local machine the CWD is the root folder so the relative path works, And it seems the CWD is somewhat different on vercel runtime.

Also it's worthy to note where the local assets should be placed, so that devs could be less confused.
@KagamiChan KagamiChan requested review from jh3y and timeyoutakeit and removed request for a team April 22, 2024 18:58
@ijjk ijjk added the Documentation Related to Next.js' official documentation. label Apr 22, 2024
@ijjk
Copy link
Member

ijjk commented Apr 22, 2024

Allow CI Workflow Run

  • approve CI run for commit: 9bc9f9c

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk
Copy link
Member

ijjk commented Apr 22, 2024

Allow CI Workflow Run

  • approve CI run for commit: 037321d

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks!

@KagamiChan
Copy link
Contributor Author

@styfle / @ijjk Thanks for the comments. I've updated as per the discussions. Please help review again.

@ijjk ijjk merged commit 769a19e into vercel:canary Apr 23, 2024
33 checks passed
@github-actions github-actions bot added the locked label May 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Related to Next.js' official documentation. locked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants