Skip to content

Commit

Permalink
Merge pull request #6 from Wikidata-Cameroon/dev
Browse files Browse the repository at this point in the history
Did api versioning
  • Loading branch information
VictorNico authored Aug 11, 2024
2 parents f825456 + bcce03d commit 194109b
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 27 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run pre-commit
49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# wiki-lex-match

__table of content__
**table of content**

- [local setup](#setup-repo-locally)
- [how to render the](#how-to-render-the-documentation)
Expand All @@ -9,7 +9,7 @@ __table of content__
## setup repo locally

- Clone repo with

```bash
git clone git@github.com:Wikidata-Cameroon/WMA_HackKmer_Yaounde_Backend.git wiki-lex-match-backend
```
Expand All @@ -20,27 +20,48 @@ __table of content__
cd wiki-lex-match-backend
```

- Run the following command on your terminal to install packages and dependencies with npm

```bash
npm install
# or npm i for short
```

### Note

- If you do not have node or npm installed to your machine, download and install the runtime from [node](https://nodejs.org/en/download/package-manager)

## How to start server

- Start local server in watch mode

```bash
npm run dev
```
```bash
npm run dev
```

- Generate Project Build

- Build to js
```bash
npm run build
```

```bash
npm run build
```
- Visit API locally through

```bash
http://localhost/8080

# You can navigate to API version 1 (the current latest version)
http://localhost/8080/api/v1
```

## Contributing

- __Git flow__
- **Git flow**

- Branches should be name with `feature/<task>` format

- Writing commits

- Commit messages should follow the for mat `#<issue_number> | <author_name> | <work_description>`

- @example is `"|#1 | @rashjredmund | installed express and configured base project template. setup hustky, prettier, and eslint. also updated readme file"`
Expand All @@ -59,8 +80,8 @@ __table of content__

- Always assign the PR to yourself and your team-mate

- __Building__
- **Building**

- Navigate to `src/modules/<your_module_of_concern>` to start contributing

- Set up your routes in the `src/route/*` directory in the right file or add one if need be
Expand All @@ -69,6 +90,6 @@ __table of content__

|

___
---

__Happy Coding Everyone 🚀__
**Happy Coding Everyone 🚀**
29 changes: 25 additions & 4 deletions public/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,31 @@ <h1 class="font-semibold text-xl md:text-2xl text-blue-500">
target="_blank">@rebase code camp</a>
</p>

<a href="/api-docs"
class="bg-slate-900 rounded px-8 py-3 text-white duration-300 hover:scale-[1.02] cursor-pointer mt-6">
API docs
</a>
<div class="w-[min(350px,_91vw)] flex flex-col items-center justify-center gap-4">
<div class="w-full flex items-center justify-center flex-nowrap gap-4">
<a href="/api/v1/"
class="bg-blue-500 rounded px-8 py-3 text-white duration-300 hover:scale-[1.02] cursor-pointer mt-6">
API V1
</a>

<a href="/api-docs"
class="bg-slate-900 rounded px-8 py-3 text-white duration-300 hover:scale-[1.02] cursor-pointer mt-6">
API docs
</a>
</div>

<div class="w-full flex items-center justify-center flex-nowrap gap-4">
<a href="/api/v2/"
class="bg-gray-500 rounded px-8 py-3 text-white duration-300 hover:scale-[1.02] cursor-pointer mt-6">
API V2
</a>

<a href="#"
class="bg-gray-500 rounded px-8 py-3 text-white duration-300 hover:scale-[1.02] cursor-pointer mt-6">
API docs
</a>
</div>
</div>
</main>
</body>

Expand Down
18 changes: 18 additions & 0 deletions src/api/v1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Router } from "express";
import { authRouter } from "./routes/auth-router";
import { languageRouter } from "./routes/language-router";
import { matchRouter } from "./routes/match-router";

const routerV1 = Router();

routerV1.get("/", (_, res) => {
return res.status(200).json({
message: "🚀 wiki-lex-match V1 🚀",
});
});

routerV1.use("/auth", authRouter);
routerV1.use("/languages", languageRouter);
routerV1.use("/match", matchRouter);

export default routerV1;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions src/api/v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Router } from "express";

const routerV2 = Router();

routerV2.get("/", (_, res) => {
return res.status(200).json({
message: "🚀 wiki-lex-match V2 🚀",
});
});

routerV2.get("*", (_, res) => {
return res.status(200).json({
message: "API v2 is not yet available",
});
});

export default routerV2;
8 changes: 2 additions & 6 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import express, { type Application } from "express";
import { authRouter } from "../routes/auth-router";
import { languageRouter } from "../routes/language-router";
import { matchRouter } from "../routes/match-router";
import path from "path";
import cors, { type CorsOptions } from "cors";

Expand All @@ -26,9 +23,8 @@ export default async (app: Application) => {
.sendFile(path.join(__dirname, "../../public/api-docs/index.html"));
});

app.use("/auth", authRouter);
app.use("/languages", languageRouter);
app.use("/match", matchRouter);
app.use("/api/v1/", (await import("../api/v1")).default);
app.use("/api/v2/", (await import("../api/v2")).default);

app.get("/health", (_, res) => {
res.status(200).json({
Expand Down

0 comments on commit 194109b

Please sign in to comment.