diff options
Diffstat (limited to 'packages/server/src/api/v1.ts')
-rw-r--r-- | packages/server/src/api/v1.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/server/src/api/v1.ts b/packages/server/src/api/v1.ts index e6391a0..b75c473 100644 --- a/packages/server/src/api/v1.ts +++ b/packages/server/src/api/v1.ts @@ -6,6 +6,13 @@ import { GitAPI } from "./git"; export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: any) { const git = new GitAPI(opts.config.settings.base_dir); + fastify.setErrorHandler((err, req, reply) => { + reply.code(500).send({ error: "Internal server error!" }); + }); + fastify.setNotFoundHandler((req, reply) => { + reply.code(404).send({ error: "Endpoint not found!" }); + }) + fastify.route({ method: "GET", url: "/info", @@ -107,6 +114,43 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do } }); + fastify_repo.route({ + method: "GET", + url: "/branches", + handler: async(req, reply) => { + const params: any = req.params; + const branches = await git.getBranches(params.repo); + + reply.send({ data: branches }); + } + }); + + fastify_repo.route({ + method: "GET", + url: "/branches/:branch", + handler: async(req, reply) => { + const params: any = req.params; + const branch = await git.getBranch(params.repo, params.branch); + + if(!branch) { + reply.code(404).send({ error: "Branch not found!" }); + return; + } + + reply.send({ data: branch }); + } + }); + + fastify_repo.route({ + method: "GET", + url: "/tags", + handler: async(req, reply) => { + const params: any = req.params; + const refs = await git.getTags(params.repo); + reply.send({ data: refs }); + } + }); + done_repo(); }, { prefix: "/repos/:repo" }); |