Added adv routing

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2022-04-20 02:49:40 +05:30
parent 4578c047d4
commit 422e9bbc36
1 changed files with 37 additions and 5 deletions

View File

@ -16,7 +16,7 @@ app.use(morgan("dev"));
// Info GET endpoint // Info GET endpoint
app.get("/info", (req, res, next) => { app.get("/info", (req, res, next) => {
res.send( res.send(
"This is a proxy service which proxies to Billing and Account APIs." "This is a simple API server that proxies requests to the Github API.\n"
); );
}); });
@ -29,17 +29,49 @@ app.use(" ", (req, res, next) => {
} }
}); });
// Proxy endpoints // Home GET endpoint to Redirect to Info
app.get("/", (req, res, next) => {
res.redirect("/info");
});
// Proxy endpoints for user
app.use( app.use(
"/fetch_json", "/gh_users/:username",
createProxyMiddleware({ createProxyMiddleware({
target: API_SERVICE_URL, target: API_SERVICE_URL + "/users",
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
[`^/fetch_json`]: "", [`^/gh_users`]: "",
}, },
}) })
); );
app.use("/gh_users", (req, res, next) => {
res.json({
message: "mention username as url parameter",
});
});
// Proxy endpoints for repositories
app.use(
"/gh_repos/:username/:repository",
createProxyMiddleware({
target: API_SERVICE_URL + "/repos",
changeOrigin: true,
pathRewrite: {
[`^/gh_repos`]: "",
},
})
);
app.use("/gh_repos/:username", (req, res, next) => {
res.json({
message: "mention repo name as url parameter",
});
});
app.use("/gh_repos", (req, res, next) => {
res.json({
message: "mention username as url parameter",
});
});
// Start the Proxy // Start the Proxy
app.listen(PORT, HOST, () => { app.listen(PORT, HOST, () => {