mirror of
https://github.com/marcogll/formbricks_form_manager.git
synced 2026-01-13 13:25:17 +00:00
feat: Add Formbricks API connection test script and debug logging for survey fetches.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -13,11 +13,16 @@ router.get("/:root/:survey", (req, res) => {
|
|||||||
`Found surveyId: ${surveyId}, environmentId: ${environmentId}, type: ${type}`
|
`Found surveyId: ${surveyId}, environmentId: ${environmentId}, type: ${type}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Redirect link surveys to Formbricks
|
// Redirect link surveys to Formbricks (via intermediate page for OG tags)
|
||||||
if (type === "link") {
|
if (type === "link") {
|
||||||
const redirectUrl = `${process.env.FORMBRICKS_SDK_URL}/s/${surveyId}`;
|
const redirectUrl = `${process.env.FORMBRICKS_SDK_URL}/s/${surveyId}`;
|
||||||
console.log(`Redirecting to: ${redirectUrl}`);
|
console.log(`Rendering redirect page for: ${redirectUrl}`);
|
||||||
return res.redirect(redirectUrl);
|
return res.render("redirect", {
|
||||||
|
title: "Vanity | formbricks",
|
||||||
|
redirectUrl: redirectUrl,
|
||||||
|
currentUrl: `${process.env.BASE_DOMAIN}/${root}/${survey}`,
|
||||||
|
baseDomain: process.env.BASE_DOMAIN,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embed app surveys
|
// Embed app surveys
|
||||||
@@ -26,6 +31,7 @@ router.get("/:root/:survey", (req, res) => {
|
|||||||
surveyId: surveyId,
|
surveyId: surveyId,
|
||||||
formbricksSdkUrl: process.env.FORMBRICKS_SDK_URL,
|
formbricksSdkUrl: process.env.FORMBRICKS_SDK_URL,
|
||||||
formbricksEnvId: environmentId,
|
formbricksEnvId: environmentId,
|
||||||
|
baseDomain: process.env.BASE_DOMAIN,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("Survey not found");
|
console.log("Survey not found");
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ app.set("views", path.join(__dirname, "views"));
|
|||||||
// Middleware
|
// Middleware
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
app.use("/assets", express.static(path.join(__dirname, "../assets")));
|
||||||
|
|
||||||
// Health check endpoint
|
// Health check endpoint
|
||||||
app.get("/health", (req, res) => {
|
app.get("/health", (req, res) => {
|
||||||
|
|||||||
@@ -58,15 +58,22 @@ async function fetchSurveysFromAPI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(
|
const url = `${process.env.FORMBRICKS_SDK_URL}/api/v1/management/surveys`;
|
||||||
`${process.env.FORMBRICKS_SDK_URL}/api/v1/management/surveys`,
|
console.log(`[DEBUG] Fetching surveys from: ${url}`);
|
||||||
{
|
console.log(
|
||||||
|
`[DEBUG] API Key starts with: ${
|
||||||
|
process.env.FORMBRICKS_API_KEY
|
||||||
|
? process.env.FORMBRICKS_API_KEY.substring(0, 4)
|
||||||
|
: "undefined"
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"x-api-key": process.env.FORMBRICKS_API_KEY,
|
"x-api-key": process.env.FORMBRICKS_API_KEY,
|
||||||
},
|
},
|
||||||
timeout: 15000, // 15 seconds timeout
|
timeout: 15000, // 15 seconds timeout
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return Array.isArray(response.data?.data) ? response.data.data : [];
|
return Array.isArray(response.data?.data) ? response.data.data : [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
43
src/views/redirect.ejs
Normal file
43
src/views/redirect.ejs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title><%= title %></title>
|
||||||
|
|
||||||
|
<!-- Open Graph / Facebook -->
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:url" content="<%= currentUrl %>">
|
||||||
|
<meta property="og:title" content="Vanity | formbricks">
|
||||||
|
<meta property="og:description" content="Please complete this survey.">
|
||||||
|
<meta property="og:image" content="<%= baseDomain %>/assets/banner_link.png">
|
||||||
|
|
||||||
|
<!-- Twitter -->
|
||||||
|
<meta property="twitter:card" content="summary_large_image">
|
||||||
|
<meta property="twitter:url" content="<%= currentUrl %>">
|
||||||
|
<meta property="twitter:title" content="Vanity | formbricks">
|
||||||
|
<meta property="twitter:description" content="Please complete this survey.">
|
||||||
|
<meta property="twitter:image" content="<%= baseDomain %>/assets/banner_link.png">
|
||||||
|
|
||||||
|
<meta http-equiv="refresh" content="0;url=<%= redirectUrl %>">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
color: #65676b;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Redirecting to survey...</p>
|
||||||
|
<script>
|
||||||
|
window.location.href = "<%= redirectUrl %>";
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -4,6 +4,18 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title><%= title %></title>
|
<title><%= title %></title>
|
||||||
|
|
||||||
|
<!-- Open Graph / Facebook -->
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:title" content="Vanity | formbricks">
|
||||||
|
<meta property="og:description" content="Please complete this survey.">
|
||||||
|
<meta property="og:image" content="<%= baseDomain %>/assets/banner_link.png">
|
||||||
|
|
||||||
|
<!-- Twitter -->
|
||||||
|
<meta property="twitter:card" content="summary_large_image">
|
||||||
|
<meta property="twitter:title" content="Vanity | formbricks">
|
||||||
|
<meta property="twitter:description" content="Please complete this survey.">
|
||||||
|
<meta property="twitter:image" content="<%= baseDomain %>/assets/banner_link.png">
|
||||||
<style>
|
<style>
|
||||||
body, html {
|
body, html {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
30
test-connection.js
Normal file
30
test-connection.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const axios = require("axios");
|
||||||
|
require("dotenv").config();
|
||||||
|
|
||||||
|
const url = `${process.env.FORMBRICKS_SDK_URL}/api/v1/management/surveys`;
|
||||||
|
console.log(`Testing connection to: ${url}`);
|
||||||
|
|
||||||
|
axios
|
||||||
|
.get(url, {
|
||||||
|
headers: {
|
||||||
|
"x-api-key": process.env.FORMBRICKS_API_KEY,
|
||||||
|
},
|
||||||
|
timeout: 15000,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log("Success!");
|
||||||
|
console.log("Status:", response.status);
|
||||||
|
console.log(
|
||||||
|
"Data length:",
|
||||||
|
Array.isArray(response.data?.data)
|
||||||
|
? response.data.data.length
|
||||||
|
: "Not an array"
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error:", error.message);
|
||||||
|
if (error.code) console.error("Code:", error.code);
|
||||||
|
if (error.response) {
|
||||||
|
console.error("Response Status:", error.response.status);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user