Skip to content

Commit

Permalink
add resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
jipsonminibhavan committed Jan 15, 2024
1 parent 7c1fda9 commit ad3cd85
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
Binary file modified .DS_Store
Binary file not shown.
23 changes: 12 additions & 11 deletions resolver/package-lock.json

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

2 changes: 1 addition & 1 deletion resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/server.js",
"scripts": {
"dev": "concurrently \"tsc --watch\" \"nodemon ./dist/server.js\"",
"start": "node ./dist/index.js",
"start": "node ./dist/server.js",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
4 changes: 2 additions & 2 deletions resolver/src/models/Link.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import mongoose, { Schema, Document } from "mongoose";

export interface ILink extends Document {
slug: string;
path: string;
url: string;
}

const linkSchema = new Schema<ILink>({
slug: { type: String, required: true, unique: true },
path: { type: String, required: true, unique: true },
url: { type: String, required: true },
});

Expand Down
19 changes: 19 additions & 0 deletions resolver/src/routes/linkRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from "express";
import Link from "../models/Link";

const router = express.Router();
router.get("/:path", async (req, res) => {
try {
const path = req.params.path;
const link = await Link.findOne({ path: path });

if (link) {
res.redirect(link.url);
} else {
res.status(404).send("URL not found");
}
} catch (error) {
res.status(500).send("Server error");
}
});
export default router;
4 changes: 2 additions & 2 deletions resolver/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import App from "./app";

const app = new App([]);
import linkRoutes from "./routes/linkRoutes";
const app = new App([linkRoutes]);

app.listen();

0 comments on commit ad3cd85

Please sign in to comment.