use nextjs built-in cors approach for formbricks app

This commit is contained in:
Matthias Nannt
2023-01-21 11:19:57 +01:00
parent 81f26e3eb6
commit 7bf0a76f29
6 changed files with 702 additions and 606 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ const nextConfig = {
return [
{
// matching all API routes
source: "/api/capture/:path*",
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
+14 -15
View File
@@ -12,23 +12,22 @@
"@formbricks/charts": "workspace:*",
"@formbricks/react": "workspace:*",
"@formbricks/ui": "workspace:*",
"@headlessui/react": "^1.7.4",
"@headlessui/react": "^1.7.7",
"@heroicons/react": "^2.0.13",
"@sentry/nextjs": "^7.24.2",
"@vercel/analytics": "^0.1.5",
"@sentry/nextjs": "^7.31.1",
"@vercel/analytics": "^0.1.8",
"bcryptjs": "^2.4.3",
"clsx": "^1.2.1",
"date-fns": "^2.29.3",
"jsonwebtoken": "^8.5.1",
"next": "^13.0.5",
"next-auth": "^4.17.0",
"nextjs-cors": "^2.1.2",
"nodemailer": "^6.8.0",
"jsonwebtoken": "^9.0.0",
"next": "^13.1.4",
"next-auth": "^4.18.8",
"nodemailer": "^6.9.0",
"platform": "^1.3.6",
"prismjs": "^1.29.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-icons": "^4.7.1",
"react-loader-spinner": "^5.3.4",
"react-toastify": "^9.1.1",
"swr": "^1.3.0"
@@ -37,13 +36,13 @@
"@formbricks/database": "workspace:*",
"@formbricks/tailwind-config": "workspace:*",
"@formbricks/tsconfig": "workspace:*",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/node": "^18.11.18",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"autoprefixer": "^10.4.13",
"eslint": "^8.28.0",
"eslint": "^8.32.0",
"eslint-config-formbricks": "workspace:*",
"postcss": "^8.4.19",
"typescript": "^4.9.3"
"postcss": "^8.4.21",
"typescript": "^4.9.4"
}
}
@@ -1,22 +1,19 @@
import { prisma } from "@formbricks/database";
import type { NextApiRequest, NextApiResponse } from "next";
import NextCors from "nextjs-cors";
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
await NextCors(req, res, {
// Options
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: "*",
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
});
const formId = req.query.formId.toString();
// CORS
if (req.method === "OPTIONS") {
res.status(200).end();
}
// POST/capture/forms/[formId]/schema
// Update form schema
// Required fields in body: -
// Optional fields in body: customerId, data
if (req.method === "POST") {
else if (req.method === "POST") {
const schema = req.body;
// create form in db
@@ -3,24 +3,21 @@ import { capturePosthogEvent } from "@/lib/posthog";
import { captureTelemetry } from "@/lib/telemetry";
import { prisma } from "@formbricks/database";
import type { NextApiRequest, NextApiResponse } from "next";
import NextCors from "nextjs-cors";
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
await NextCors(req, res, {
// Options
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: "*",
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
});
const formId = req.query.formId.toString();
const submissionId = req.query.submissionId.toString();
// CORS
if (req.method === "OPTIONS") {
res.status(200).end();
}
// PUT /capture/forms/[formId]/submissions/[submissionId]
// Extend an existing form submission
// Required fields in body: -
// Optional fields in body: customerId, data
if (req.method === "PUT") {
else if (req.method === "PUT") {
const submission = req.body;
// get form
@@ -3,23 +3,20 @@ import { capturePosthogEvent } from "@/lib/posthog";
import { captureTelemetry } from "@/lib/telemetry";
import { prisma } from "@formbricks/database";
import type { NextApiRequest, NextApiResponse } from "next";
import NextCors from "nextjs-cors";
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
await NextCors(req, res, {
// Options
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
origin: "*",
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
});
const formId = req.query.formId.toString();
// CORS
if (req.method === "OPTIONS") {
res.status(200).end();
}
// POST/capture/forms/[formId]/submissions
// Create a new form submission
// Required fields in body: -
// Optional fields in body: customerId, data
if (req.method === "POST") {
else if (req.method === "POST") {
const submission = req.body;
// get form
+669 -563
View File
File diff suppressed because it is too large Load Diff