Skip to content

Commit

Permalink
fix: middleware cors update
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalavedra committed Aug 7, 2024
1 parent ca584a0 commit de085e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
4 changes: 3 additions & 1 deletion examples/apps/auth-sample/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
module.exports = {
const nextConfig = {
reactStrictMode: true,
};

module.exports = nextConfig;
22 changes: 22 additions & 0 deletions examples/apps/auth-sample/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";

export function middleware() {
// retrieve the current response
const res = NextResponse.next()

// add the CORS headers to the response
res.headers.append('Access-Control-Allow-Credentials', "true")
res.headers.append('Access-Control-Allow-Origin', '*') // replace this your actual origin
res.headers.append('Access-Control-Allow-Methods', 'GET,DELETE,PATCH,POST,PUT')
res.headers.append(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
)

return res
}

// specify the path regex to apply the middleware to
export const config = {
matcher: '/api/:path*',
}
21 changes: 0 additions & 21 deletions examples/apps/auth-sample/src/pages/middleware.ts

This file was deleted.

0 comments on commit de085e2

Please sign in to comment.