Add DevConnect REST proxy endpoints
cgen-7c7ff5d7669445c993a75e5db251f2ae
This commit is contained in:
parent
eb8d014737
commit
bd9a28f1b1
1 changed files with 25 additions and 0 deletions
|
|
@ -19,6 +19,31 @@ export function createServer() {
|
||||||
res.json({ message: ping });
|
res.json({ message: ping });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// DevConnect REST proxy (GET only)
|
||||||
|
app.get("/api/devconnect/rest/:table", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const base = process.env.DEVCONNECT_URL;
|
||||||
|
const key = process.env.DEVCONNECT_ANON_KEY;
|
||||||
|
if (!base || !key) return res.status(500).json({ error: "DevConnect env not set" });
|
||||||
|
const table = String(req.params.table || "").replace(/[^a-zA-Z0-9_]/g, "");
|
||||||
|
const qs = req.url.includes("?") ? req.url.substring(req.url.indexOf("?")) : "";
|
||||||
|
const url = `${base}/rest/v1/${table}${qs}`;
|
||||||
|
const r = await fetch(url, {
|
||||||
|
headers: {
|
||||||
|
apikey: key,
|
||||||
|
Authorization: `Bearer ${key}`,
|
||||||
|
Accept: "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const text = await r.text();
|
||||||
|
if (!r.ok) return res.status(r.status).send(text);
|
||||||
|
res.setHeader("content-type", r.headers.get("content-type") || "application/json");
|
||||||
|
return res.status(200).send(text);
|
||||||
|
} catch (e: any) {
|
||||||
|
return res.status(500).json({ error: e?.message || String(e) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.post("/api/auth/send-verification-email", async (req, res) => {
|
app.post("/api/auth/send-verification-email", async (req, res) => {
|
||||||
const { email, redirectTo, fullName } = (req.body || {}) as {
|
const { email, redirectTo, fullName } = (req.body || {}) as {
|
||||||
email?: string;
|
email?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue