https://supertokens.com/ logo
#support-questions
Title
# support-questions
g

gusfune

07/08/2021, 10:36 AM
Copy code
ts
import { NextApiRequest, NextApiResponse } from "next"
import NextCors from "nextjs-cors"
import { superTokensNextWrapper } from "supertokens-node/nextjs"
import { middleware, init, getAllCORSHeaders } from "supertokens-node"
import { backendConfig } from "../../../data/supertokens"

init(backendConfig())

export default async function superTokens(
  req: NextApiRequest,
  res: NextApiResponse
) {
  await NextCors(req, res, {
    methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
    origin: [/\.offscript\.io$/, /\.vercel\.app$/],
    credentials: true,
    allowedHeaders: ["content-type", ...getAllCORSHeaders()],
  })
  await superTokensNextWrapper(
    async (next) => {
      await middleware()(req, res, next)
    },
    req,
    res
  )
  if (!res.writableEnded) {
    res.status(404).send("Not found")
  }
}