Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const sdk = require("node-appwrite");

export default async function handler(req, res) {
const { shortCode } = req.query;

console.log("shortCode", shortCode);

if (!shortCode) {
return res.status(400).json({ error: "shortCode is required" });
}

// Initialize Appwrite client
const client = new sdk.Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_PROJECT);

const database = new sdk.Databases(client);

try {
// Retrieve the document by shortCode
const result = await database.getDocument(
process.env.URL_DB,
process.env.URL_COL,
shortCode
);

const longURL = result.longURL;

// Redirect to the original URL
return res.redirect(302, longURL);
} catch (error) {
return res.status(404).json({ error: error.message });
}
}
23 changes: 23 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/node-appwrite/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions node_modules/node-appwrite/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions node_modules/node-appwrite/dist/client.d.mts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading