Skip to content

Commit 90600a2

Browse files
chore(examples): use nextjs proxy instead of middleware
1 parent dfba600 commit 90600a2

6 files changed

Lines changed: 15 additions & 15 deletions

File tree

examples/nextjs/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This example aims to test the `js-auth` library on Vercel and Netlify edges.
1717
### Test link
1818

1919
- https://commercelayer-js-auth-nextjs.vercel.app/
20-
- https://commercelayer-js-auth-nextjs.vercel.app/middleware
20+
- https://commercelayer-js-auth-nextjs.vercel.app/proxy
2121
- https://commercelayer-js-auth-nextjs.vercel.app/api/test
2222

2323
## Netlify
@@ -34,5 +34,5 @@ This example aims to test the `js-auth` library on Vercel and Netlify edges.
3434
### Test link
3535

3636
- https://commercelayer-js-auth-nextjs.netlify.app/
37-
- https://commercelayer-js-auth-nextjs.netlify.app/middleware
37+
- https://commercelayer-js-auth-nextjs.netlify.app/proxy
3838
- https://commercelayer-js-auth-nextjs.netlify.app/api/test

examples/nextjs/src/components/DefaultTemplate.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Image from "next/image"
1+
22
import styles from "./DefaultTemplate.module.css"
33

44
export default function DefaultTemplate({
@@ -9,23 +9,23 @@ export default function DefaultTemplate({
99
<main className={styles.main}>
1010
<div className={styles.description}>
1111
<p>{title}</p>
12-
<a href='/'>Back to home</a>
12+
<a href="/">Back to home</a>
1313
</div>
1414

1515
<div className={styles.center}>{children}</div>
1616

1717
<div className={styles.grid}>
1818
<a
19-
href="/middleware"
19+
href="/proxy"
2020
className={styles.card}
2121
target="_blank"
2222
rel="noopener noreferrer"
2323
>
2424
<h2>
25-
Middleware <span>-&gt;</span>
25+
Proxy <span>-&gt;</span>
2626
</h2>
2727
<p>
28-
<code>auth.js</code> within a middleware.
28+
<code>auth.js</code> within a proxy.
2929
</p>
3030
</a>
3131

examples/nextjs/src/middlewares/types.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { NextProxy } from "next/server"
2+
3+
export type WithProxy = (next?: NextProxy) => NextProxy

examples/nextjs/src/middlewares/withCommerceLayer.ts renamed to examples/nextjs/src/proxies/withCommerceLayer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import { NextResponse } from 'next/server'
88
import { createStorage } from "unstorage"
99
import memoryDriver from "unstorage/drivers/memory"
1010
import { makeCustomerStorage } from "@/app/utils/customerStorage"
11-
import type { WithMiddleware } from "./types"
11+
import type { WithProxy } from "./types"
1212

1313
const clientId = process.env.NEXT_PUBLIC_CLIENT_ID as string
1414
const scope = process.env.NEXT_PUBLIC_SCOPE as string
1515

16-
export const withCommerceLayer: WithMiddleware = (
16+
export const withCommerceLayer: WithProxy = (
1717
_next = () => NextResponse.next(),
1818
) => {
1919
return async (request, _event) => {
20-
if (request.nextUrl.pathname.endsWith("/middleware")) {
20+
if (request.nextUrl.pathname.endsWith("/proxy")) {
2121
const auth = await authenticate("client_credentials", {
2222
clientId,
2323
scope,
@@ -30,7 +30,7 @@ export const withCommerceLayer: WithMiddleware = (
3030
}
3131

3232
return NextResponse.json({
33-
from: "middleware",
33+
from: "proxy",
3434
orgSlug: decodedJWT.payload.organization.slug,
3535
baseEndpoint: getCoreApiBaseEndpoint(auth.accessToken),
3636
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withCommerceLayer } from './middlewares/withCommerceLayer'
1+
import { withCommerceLayer } from './proxies/withCommerceLayer'
22

33
export default withCommerceLayer()
44

0 commit comments

Comments
 (0)