Skip to content

Commit

Permalink
refactor: rename cors middleware
Browse files Browse the repository at this point in the history
Signed-off-by: ayushnirwal <[email protected]>
  • Loading branch information
ayushnirwal committed Jan 30, 2025
1 parent a34a400 commit dd322c9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/nextjs/starter/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { appMiddlewares, type MiddlewareFactory, corsMiddleware } from '@snapwp/next';
import { appMiddlewares, type MiddlewareFactory, corsProxyMiddleware } from '@snapwp/next';

/**
* Layer your own custom middlewares here by adding them to the array.
Expand All @@ -7,7 +7,7 @@ import { appMiddlewares, type MiddlewareFactory, corsMiddleware } from '@snapwp/
*/
const middleware: MiddlewareFactory[] = [
// Proxies WordPress assets (scripts, theme files, etc) to prevent CORS issues on localhost.
corsMiddleware
corsProxyMiddleware
];

export default appMiddlewares( middleware );
2 changes: 1 addition & 1 deletion packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { currentPath } from './middleware/current-path';
export { proxies } from './middleware/proxies';
export * from './middleware/utils';
export { cors as corsMiddleware } from './middleware/cors';
export * from './middleware/cors';
export * from './template-renderer';
export * from './root-layout';
export { default as Parse } from './react-parser';
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { MiddlewareFactory } from './utils';
*
* @param next

Check warning on line 8 in packages/next/src/middleware/cors.ts

View workflow job for this annotation

GitHub Actions / ESLint

Missing JSDoc @param "next" description
*/
export const cors: MiddlewareFactory = ( next: NextMiddleware ) => {
export const corsProxyMiddleware: MiddlewareFactory = (
next: NextMiddleware
) => {
return async ( request: NextRequest, _next: NextFetchEvent ) => {
const { homeUrl, corsProxyPrefix } = getConfig();

Expand Down
1 change: 0 additions & 1 deletion packages/next/src/middleware/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextMiddleware, NextResponse } from 'next/server';
import { proxies } from './proxies';
import { currentPath as cm } from './current-path';
import { cors } from './cors';

export type MiddlewareFactory = (
middleware: NextMiddleware
Expand Down

0 comments on commit dd322c9

Please sign in to comment.