Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"packages/sdk/react-native",
"packages/sdk/react-native/example",
"packages/sdk/vercel",
"packages/sdk/vercel/examples/complete",
"packages/sdk/vercel/examples/route-handler",
Comment on lines +16 to +17
Copy link
Contributor Author

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.

"packages/sdk/akamai-base",
"packages/sdk/akamai-base/example",
"packages/sdk/akamai-edgekv",
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/vercel/examples/complete/.eslintrc.json
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"]
}
25 changes: 14 additions & 11 deletions packages/sdk/vercel/examples/complete/middleware.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Up @@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how this example could have worked? request does not exist.

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(
Expand All @@ -43,20 +46,20 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {
);

return hotDogFaviconEnabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same applies to request here as above.

? 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;
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/vercel/examples/complete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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",
Expand Down
8 changes: 0 additions & 8 deletions packages/sdk/vercel/examples/route-handler/next.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/sdk/vercel/examples/route-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

doc never exists in this project, so this was breaking.

},
"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": {
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/vercel/src/utils/mockEdgeConfigClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const mockEdgeConfigClient: EdgeConfigClient = {
getAll: jest.fn(),
digest: jest.fn(),
has: jest.fn(),
connection: {
baseUrl: '',
id: '',
token: '',
version: '',
type: 'vercel',
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;