generated from ScottyLabs/fullstack-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92fba18
commit 9f3e388
Showing
31 changed files
with
799 additions
and
703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { getAuth } from '@clerk/nextjs/server'; | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
import { NextRequest } from 'next/server'; | ||
import { createTRPCContext } from 'server/trpc/context'; | ||
import { appRouter } from 'server/trpc/router/_app'; | ||
|
||
/** | ||
* Configure basic CORS headers | ||
* You should extend this to match your needs | ||
*/ | ||
function setCorsHeaders(res: Response) { | ||
res.headers.set('Access-Control-Allow-Origin', '*'); | ||
res.headers.set('Access-Control-Request-Method', '*'); | ||
res.headers.set('Access-Control-Allow-Methods', 'OPTIONS, GET, POST'); | ||
res.headers.set('Access-Control-Allow-Headers', '*'); | ||
} | ||
|
||
export function OPTIONS() { | ||
const response = new Response(null, { | ||
status: 204 | ||
}); | ||
setCorsHeaders(response); | ||
return response; | ||
} | ||
|
||
const handler = async (req: NextRequest) => { | ||
const response = await fetchRequestHandler({ | ||
endpoint: '/api/trpc', | ||
router: appRouter, | ||
req, | ||
createContext: () => | ||
createTRPCContext({ | ||
session: getAuth(req), | ||
headers: req.headers | ||
}), | ||
onError({ error, path }) { | ||
console.error(`>>> tRPC Error on '${path}'`, error); | ||
} | ||
}); | ||
|
||
setCorsHeaders(response); | ||
return response; | ||
}; | ||
|
||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.