-
Notifications
You must be signed in to change notification settings - Fork 31
/
api.ts
41 lines (32 loc) · 874 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import express from "express";
import cors from "cors";
import { isAuthed } from "./utils/auth";
import { html2md, url2md } from "./routers";
export const app = express();
app.use(cors({ origin: true }));
app.use(express.json());
app.use(express.raw({ type: "application/vnd.custom-type" }));
app.use(express.text({ type: "text/html" }));
// Healthcheck endpoint
app.get("/", (req, res) => {
res.status(200).send({ status: "ok" });
});
const api = express.Router();
api.get("/hello", (req, res) => {
res.status(200).send({ message: "hello world" });
});
api.get("/url2md", url2md);
api.post("/html2md", html2md);
// Version the api
app.use(
"/api",
(req, res, next) => {
const authorization = req.headers.authorization;
if (!isAuthed(authorization)) {
res.status(401).end("Unauthorized request");
return;
}
next();
},
api
);