Skip to content

Commit

Permalink
docs: added api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Nandan Sharma authored and Raj Nandan Sharma committed Nov 19, 2024
1 parent ad41edc commit 71b56db
Show file tree
Hide file tree
Showing 8 changed files with 1,796 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ COPY --chown=abc:abc static /app/static
COPY --chown=abc:abc database /app/database
COPY --chown=abc:abc build.js /app/build.js
COPY --chown=abc:abc sitemap.js /app/sitemap.js
COPY --chown=abc:abc openapi.json /app/openapi.json
COPY --chown=abc:abc src/lib/server /app/src/lib/server
COPY --chown=abc:abc src/lib/helpers.js /app/src/lib/helpers.js

Expand Down
18 changes: 18 additions & 0 deletions docs/kener-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ export API_TOKEN=some-token-set-by-you

Additonally you can set IP whitelisting by setting another environment token called `API_IP` or `API_IP_REGEX`. If you set both `API_IP` and `API_IP_REGEX`, `API_IP` will be given preference. Read more [here](/docs/environment-vars#api_ip)

## Interactive API Reference

<p class="border p-4 rounded-md">
<picture class="inline">
<source srcset="https://fonts.gstatic.com/s/e/notoemoji/latest/1f916/512.webp" type="image/webp">
<img src="https://fonts.gstatic.com/s/e/notoemoji/latest/1f916/512.gif" alt="🤖" width="32" height="32">
</picture>
<a href="/api-reference">
Click here to view the interactive API reference
</a>

</p>

You can download the openapi spec

- [JSON](https://raw.githubusercontent.com/rajnandan1/kener/main/openapi.json)
- [YAML](https://raw.githubusercontent.com/rajnandan1/kener/main/openapi.yaml)

---

## Update Status - API
Expand Down
33 changes: 33 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { handler } from "./build/handler.js";
import { apiReference } from "@scalar/express-api-reference";
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import sitemap from "./sitemap.js";
import fs from "fs-extra";
const PORT = process.env.PORT || 3000;

const app = express();
Expand All @@ -16,10 +18,41 @@ app.use((req, res, next) => {
app.get("/healthcheck", (req, res) => {
res.end("ok");
});

try {
const openapiJSON = fs.readFileSync("./openapi.json", "utf-8");
app.use(
"/api-reference",
apiReference({
spec: {
content: openapiJSON
},
theme: "alternate",
hideModels: true,
hideTestRequestButton: true,
darkMode: true,
metaData: {
title: "Kener API Reference",
description: "Kener free open source status page API Reference",
ogDescription: "Kener free open source status page API Reference",
ogTitle: "Kener API Reference",
ogImage: "https://kener.ing/newbg.png",
twitterCard: "summary_large_image",
twitterTitle: "Kener API Reference",
twitterDescription: "Kener free open source status page API Reference",
twitterImage: "https://kener.ing/newbg.png"
},
favicon: "https://kener.ing/logo96.png"
})
);
} catch (e) {
console.warn("Error loading openapi.json, but that is okay.");
}
app.get("/sitemap.xml", (req, res) => {
res.setHeader("Content-Type", "application/xml");
res.end(sitemap);
});

app.use(handler);

app.listen(PORT, () => {
Expand Down
Loading

0 comments on commit 71b56db

Please sign in to comment.