-
Notifications
You must be signed in to change notification settings - Fork 31
fix: Update to major version of @vercel/edge-config #393
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| { | ||
| "root": true, | ||
| "extends": "next/core-web-vitals" | ||
| "extends": ["plugin:@next/next/recommended"] | ||
| } |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No functional changes here just minor refactoring for the sake of my ocd. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,32 +8,35 @@ export const config = { | |
| matcher: ['/', '/closed', '/favicon.ico'], | ||
| }; | ||
|
|
||
| export async function middleware(req: NextRequest, context: NextFetchEvent) { | ||
| export async function middleware( | ||
| { headers, method, nextUrl, url }: NextRequest, | ||
| _context: NextFetchEvent, | ||
| ) { | ||
| // for demo purposes, warn when there is no EDGE_CONFIG or LAUNCHDARKLY_CLIENT_SIDE_ID | ||
| if ( | ||
| !process.env.EDGE_CONFIG || | ||
| !process.env.LD_CLIENT_SIDE_ID || | ||
| !parseConnectionString(process.env.EDGE_CONFIG) | ||
| ) { | ||
| return NextResponse.rewrite(new URL('/missing-edge-config', request.url)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this example could have worked? |
||
| return NextResponse.rewrite(new URL('/missing-edge-config', url)); | ||
| } | ||
|
|
||
| try { | ||
| const client = await ldEdgeClient.waitForInitialization(); | ||
| const flagContext: LDMultiKindContext = { | ||
| kind: 'multi', | ||
| url: { | ||
| key: req.url, | ||
| key: url, | ||
| }, | ||
| method: { | ||
| key: req.method, | ||
| key: method, | ||
| }, | ||
| 'user-agent': { | ||
| key: req.headers.get('user-agent') || 'unknown', | ||
| key: headers.get('user-agent') || 'unknown', | ||
| }, | ||
| }; | ||
|
|
||
| const { pathname } = req.nextUrl; | ||
| const { pathname } = nextUrl; | ||
|
|
||
| if (pathname === '/favicon.ico') { | ||
| const hotDogFaviconEnabled = await client.variation( | ||
|
|
@@ -43,20 +46,20 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) { | |
| ); | ||
|
|
||
| return hotDogFaviconEnabled | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies to |
||
| ? NextResponse.rewrite(new URL('/hot-dog.ico', request.url)) | ||
| ? NextResponse.rewrite(new URL('/hot-dog.ico', url)) | ||
| : NextResponse.next(); | ||
| } | ||
|
|
||
| const storeClosed = await client.variation('store-closed', flagContext, false); | ||
|
|
||
| if (pathname === '/' && storeClosed) { | ||
| req.nextUrl.pathname = `/closed`; | ||
| return NextResponse.rewrite(new URL('/closed', req.url)); | ||
| nextUrl.pathname = `/closed`; | ||
| return NextResponse.rewrite(new URL('/closed', url)); | ||
| } | ||
|
|
||
| if (pathname === '/closed') { | ||
| req.nextUrl.pathname === '/'; | ||
| return NextResponse.redirect(new URL('/', req.url)); | ||
| nextUrl.pathname = '/'; | ||
| return NextResponse.redirect(new URL('/', url)); | ||
| } | ||
|
|
||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,16 +10,16 @@ | |
| "start": "next start" | ||
| }, | ||
| "dependencies": { | ||
| "@launchdarkly/vercel-server-sdk": "1.0.0", | ||
| "@vercel/edge-config": "0.1.10", | ||
| "@launchdarkly/vercel-server-sdk": "1.3.0", | ||
| "@vercel/edge-config": "^1.1.0", | ||
|
Comment on lines
+13
to
+14
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the main updates. |
||
| "launchdarkly-js-client-sdk": "^3.1.3", | ||
| "launchdarkly-react-client-sdk": "^3.0.6", | ||
| "next": "canary", | ||
| "react": "latest", | ||
| "react-dom": "latest" | ||
| "next": "14.1.2", | ||
| "react": "18.2.0", | ||
| "react-dom": "18.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@next/eslint-plugin-next": "^13.4.4", | ||
| "@next/eslint-plugin-next": "14.1.2", | ||
| "@types/node": "^18.15.5", | ||
| "@types/react": "latest", | ||
| "autoprefixer": "^10.4.14", | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,9 @@ | |
| "lint": "next lint" | ||
| }, | ||
| "dependencies": { | ||
| "@launchdarkly/vercel-server-sdk": "1.0.0", | ||
| "@vercel/edge-config": "^0.2.1", | ||
| "next": "^13.4.4", | ||
| "@launchdarkly/vercel-server-sdk": "1.3.0", | ||
| "@vercel/edge-config": "^1.1.0", | ||
| "next": "14.1.2", | ||
|
Comment on lines
+12
to
+14
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Major updates here too. |
||
| "react": "^18.2.0", | ||
| "react-dom": "18.2.0" | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,11 +33,11 @@ | |
| "prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore", | ||
| "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --ci --runInBand", | ||
| "coverage": "yarn test --coverage", | ||
| "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" | ||
| "check": "yarn prettier && yarn lint && yarn build && yarn test" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }, | ||
| "dependencies": { | ||
| "@launchdarkly/js-server-sdk-common-edge": "2.2.0", | ||
| "@vercel/edge-config": "^0.1.8", | ||
| "@vercel/edge-config": "^1.1.0", | ||
| "crypto-js": "^4.1.1" | ||
| }, | ||
| "devDependencies": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,13 @@ const mockEdgeConfigClient: EdgeConfigClient = { | |
| getAll: jest.fn(), | ||
| digest: jest.fn(), | ||
| has: jest.fn(), | ||
| connection: { | ||
| baseUrl: '', | ||
| id: '', | ||
| token: '', | ||
| version: '', | ||
| type: 'vercel', | ||
| }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is newly added in the major version of edge-config. |
||
| }; | ||
|
|
||
| export default mockEdgeConfigClient; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include examples in the workspace to take advantage of the monorepo setup.