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

Support new middleware cookies api #544

Merged
merged 13 commits into from
Jul 17, 2022

Conversation

huozhi
Copy link
Contributor

@huozhi huozhi commented Jul 15, 2022

x-ref: vercel/swr-site#307 (comment)

  • handle with/without trailing slash in url cases to extract correct locale
  • handle differen cookies APIs
  • add locale tests

rewrite the lcoale extracting from url logic, previously the pathname can be /, then the url with host removed can be zh-CN or zh-CN/ in with next version (12.2 vs 12.1). We'd better to find the first slash and get extract the locale from it

Thanks @promer94 for helping with setting up locale tests

@vercel
Copy link

vercel bot commented Jul 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nextra-theme-docs-dev ✅ Ready (Inspect) Visit Preview Jul 16, 2022 at 8:22PM (UTC)
1 Ignored Deployment
Name Status Preview Updated
nextra ⬜️ Ignored (Inspect) Jul 16, 2022 at 8:22PM (UTC)

Copy link
Collaborator

@promer94 promer94 left a comment

Choose a reason for hiding this comment

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

Currently the preview is broken
https://nextra-theme-docs-dev-git-fork-huozhi-fix-next-middleware-api.vercel.sh/zh-CN

I think the reason is that

const fullUrl = nextUrl.toString()

fullUrl is different between next 12.1 and next 12.2

When user access https://swr.vercel.app/zh-CN

  • 12.1
    fullUrl would be https://swr.vercel.app/zh-CN/

  • 12.2
    fullUrl would be https://swr.vercel.app/zh-CN
    It doesn't have trailing slash

@huozhi huozhi marked this pull request as draft July 16, 2022 16:20
test against actual api
@promer94 promer94 merged commit 2cc4635 into shuding:core Jul 17, 2022
@huozhi huozhi deleted the fix/next-middleware-api branch July 17, 2022 07:52
tatukoivisto pushed a commit to tatukoivisto/nextra that referenced this pull request Aug 20, 2023
* Support new middleware cookies api

* update example

* handle slashes

* fix locale rewrites

* extract locale for w/o trailing slash

* fallback /

* extract locale correctly

* fix lock

* update test snapshots

* fix non index pages i18n

* test: add locale middleware test

* test against actual api

test against actual api

* fix locale

Co-authored-by: Yixuan Xu <yixuanxu94@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants