mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-14 11:00:34 -06:00
add legacy endpoint
This commit is contained in:
@@ -22,6 +22,20 @@ const nextConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// matching all API routes
|
||||
source: "/api/capture/:path*",
|
||||
headers: [
|
||||
{ key: "Access-Control-Allow-Credentials", value: "true" },
|
||||
{ key: "Access-Control-Allow-Origin", value: "*" },
|
||||
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
||||
{
|
||||
key: "Access-Control-Allow-Headers",
|
||||
value:
|
||||
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
39
apps/web/pages/api/capture/forms/[formId]/schema/index.ts
Normal file
39
apps/web/pages/api/capture/forms/[formId]/schema/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
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
|
||||
else if (req.method === "POST") {
|
||||
if (process.env.FORMBRICKS_LEGACY_HOST) {
|
||||
const response = await fetch(
|
||||
`${process.env.FORMBRICKS_LEGACY_HOST}/api/capture/forms/${formId}/schema`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.FORMBRICKS_LEGACY_HOST}`,
|
||||
},
|
||||
body: JSON.stringify(req.body),
|
||||
}
|
||||
);
|
||||
const responseData = await response.json();
|
||||
res.json(responseData);
|
||||
} else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown HTTP Method
|
||||
else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
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
|
||||
else if (req.method === "PUT") {
|
||||
// redirect request and make a request to legacy.formbricks.com
|
||||
if (process.env.FORMBRICKS_LEGACY_HOST) {
|
||||
const response = await fetch(
|
||||
`${process.env.FORMBRICKS_LEGACY_HOST}/api/capture/forms/${formId}/submissions/${submissionId}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.FORMBRICKS_LEGACY_HOST}`,
|
||||
},
|
||||
body: JSON.stringify(req.body),
|
||||
}
|
||||
);
|
||||
const responseData = await response.json();
|
||||
res.json(responseData);
|
||||
} else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown HTTP Method
|
||||
else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
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
|
||||
else if (req.method === "POST") {
|
||||
if (process.env.FORMBRICKS_LEGACY_HOST) {
|
||||
const response = await fetch(
|
||||
`${process.env.FORMBRICKS_LEGACY_HOST}/api/capture/forms/${formId}/submissions`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.FORMBRICKS_LEGACY_HOST}`,
|
||||
},
|
||||
body: JSON.stringify(req.body),
|
||||
}
|
||||
);
|
||||
const responseData = await response.json();
|
||||
res.json(responseData);
|
||||
} else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown HTTP Method
|
||||
else {
|
||||
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
"dependsOn": ["^build"],
|
||||
"outputs": ["dist/**", ".next/**"],
|
||||
"env": [
|
||||
"FORMBRICKS_LEGACY_HOST",
|
||||
"GITHUB_ID",
|
||||
"GITHUB_SECRET",
|
||||
"MAIL_FROM",
|
||||
|
||||
Reference in New Issue
Block a user