Upgrade docs endpoint

This commit is contained in:
MartinBraquet
2025-09-16 22:28:40 +02:00
parent 1dc2a1fadf
commit 613ef94dba
3 changed files with 14 additions and 14 deletions

View File

@@ -1,13 +1,13 @@
# Backend API
This is the code for the API running at `api.compassmeet.com`.
This is the code for the API running at https://api.compassmeet.com.
It runs in a docker inside a Google Cloud virtual machine.
### Requirements
You must have the `gcloud` CLI.
On MacOS:
On macOS:
```bash
brew install --cask google-cloud-sdk
@@ -60,7 +60,7 @@ Set up the saved search notifications job:
```bash
gcloud scheduler jobs create http daily-saved-search-notifications \
--schedule="0 19 * * *" \
--schedule="0 16 * * *" \
--uri="https://api.compassmeet.com/internal/send-search-notifications" \
--http-method=POST \
--headers="x-api-key=<API_KEY>" \
@@ -155,3 +155,8 @@ docker exec -it $(sudo docker ps -alq) sh
docker run -it --rm $(docker images -q | head -n 1) sh
docker rmi -f $(docker images -aq)
```
### Documentation
The API docs are available at https://api.compassmeet.com. They are defined in [openapi.json](openapi.json).
Just a few endpoints are mentioned in that JSON doc. Feel free to help by adding the remaining ones!

View File

@@ -113,11 +113,7 @@ swaggerDocument.info = {
}
};
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.listen(process.env.PORT ?? 8088, () => {
console.log(`API UI available at /docs`)
})
app.use(pathWithPrefix(""), swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.options('*', allowCorsUnrestricted)
@@ -171,7 +167,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
Object.entries(handlers).forEach(([path, handler]) => {
const api = API[path as APIPath]
const cache = cacheController((api as any).cache)
const url = '/' + pathWithPrefix(path as APIPath)
const url = pathWithPrefix('/' + path as APIPath)
const apiRoute = [
url,
@@ -193,11 +189,10 @@ Object.entries(handlers).forEach(([path, handler]) => {
}
})
console.log('COMPASS_API_KEY:', process.env.COMPASS_API_KEY)
// console.log('COMPASS_API_KEY:', process.env.COMPASS_API_KEY)
// Internal Endpoints
app.post(
'/' + pathWithPrefix("internal/send-search-notifications"),
app.post(pathWithPrefix("/internal/send-search-notifications"),
async (req, res) => {
const apiKey = req.header("x-api-key");
if (apiKey !== process.env.COMPASS_API_KEY) {
@@ -223,7 +218,7 @@ app.use(allowCorsUnrestricted, (req, res) => {
.status(404)
.set('Content-Type', 'application/json')
.json({
message: `The requested route '${req.path}' does not exist. Please check your URL for any misspellings or refer to app.ts`,
message: `This is the Compass API, but the requested route '${req.path}' does not exist. Please check your URL for any misspellings, the docs at https://api.compassmeet.com, or simply refer to app.ts on GitHub`,
})
}
})

View File

@@ -21,7 +21,7 @@ export class APIError extends Error {
}
export function pathWithPrefix(path: string) {
return `v0/${path}`
return `/v0${path}`
}
export function getWebsocketUrl() {