diff --git a/index.js b/index.js index df23ce6..cd55556 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ app.use(morgan("dev")); // Info GET endpoint app.get("/info", (req, res, next) => { 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( - "/fetch_json", + "/gh_users/:username", createProxyMiddleware({ - target: API_SERVICE_URL, + target: API_SERVICE_URL + "/users", changeOrigin: true, 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 app.listen(PORT, HOST, () => {