This sub-project allows proxying requests to the Anixart API and modifying their responses using hooks.
It can be used both for the main AniX project and as a standalone service for the Android app with a modified API link via anixart-patcher.
License: MIT
This project has the following structure
.
├── src
│ ├── hooks
│ │ ├── index.ts - functions for running the hooks
│ │ ├── enabledHooks.ts - list of enabled hooks
│ │ ├── hook1.ts - hook file(s)
│ │ ├── ...
│ ├── json
│ │ └── file.json - json files to import in hook to use as a data storage
│ ├── utils
│ │ ├── info.ts - info functions for api-prox
│ │ ├── logger.ts - logger functions for api-prox
│ │ └── tryCatch.ts - tryCatch wrapper for async functions like fetch
│ ├── config.ts - config of api-prox
│ └── index.ts - entrypoint and route handling
├── .dockerignore
├── .gitignore
├── .vercelignore
├── bun.lock
├── bun.ts - file to run with bun
├── deno.json
├── deno.lock
├── deno.ts - file to run with deno
├── Dockerfile
├── LICENSE
├── node.ts - file to run with node
├── package-lock.json
├── package.json
├── README.md
├── tsconfig.json
├── vercel.json
└── wrangler.jsoncIn coding of this project used a Hono framework to make it run on multiple serverless platforms
Tested with following platforms:
- CloudFlare Workers
- Vercel Functions
- Deno Deploy
To access the main page enter the url of your deployed project: <http|https>://<ip|domain><:port>/<ENDPOINT>[?<QUERY_PARAMS>]
Available endpoints:
GET /- main page, how to get started with your deployGET /health- health page, version info and enabled hooksGET /health/json- same as before, but in json formatGET|POST /*- proxy the pathname and query to anixart server
Response:
- 200: request to proxy was successful
if page is not found: returned a json with {"message": <reason>, "code": 404}
if API returned a non zero code: returned a json with {"message": <reason>, "code": <code from api response>}
Hooks are a functions with a matcher that modify the API response
Type:
export type Hook = {
title: string;
description: string | null;
priority: number;
match: (url: URL, method: "GET" | "POST") => boolean;
hook: (url: URL, data: any, method: "GET" | "POST") => Promise<any>;
};Title and Descriptions will be used to show an enabled hook at a /health endpoint
To view how to write a hook, you can see the build-in hooks as a reference:
To enable the hook, you need to import it inside enabledHooks.ts, and add it to enabledHooks list inside
-
Clone the repository
git clone https://github.com/Radiquum/AniX.git
-
Install the dependencies
For CloudFlare workers / Vercel functions
npm install
For Deno deploy
deno install
-
If needed modify the config and hooks (same as in docker from step 6)
-
Deploy
CloudFlare workers
npm run cf-deploy
Vercel functions
npm run vc-deploy
Deno deploy
deno run deno-deploy
Requirements:
- docker engine
- Linux based system or WSL
- Run the command:
docker run -d --restart always --name anix-api -p 7001:7001 radiquum/anix-api-prox:latestAdditional Requirements:
- Clone the repository:
git clone https://github.com/Radiquum/AniX - Navigate to the repository directory:
cd AniX - Navigate to the service directory:
cd api-prox - Run the command:
docker build -t anix-api-prox . - After completion, run:
docker run -d --restart always --name anix-api-prox -p 7001:7001 anix-api-prox
-
create a
hooksfolder and add the flag-v ./hooks:/app/src/hooks/custombefore the
-pflag. -
do the same for json folder
-v ./json:/app/src/json/custom -
create a
enabledHooks.tsfile with the following content and link it to container with-v ./enabledHooks.ts:/app/src/hooks/enabledHooks.tsimport { Hook } from "./index.js"; export const enabledHooks: Hook[] = []; export default enabledHooks;
This will disable bundled hooks
-
Place your hooks to hooks directory at host
-
Place your json files to json directory at host
-
Import hook to enabledHooks.ts
import MyHook from "./custom/MyHook.js"
To import a json files inside a hook:
import MyJson from "../../json/custom/MyJson.json" with {"type": "json"};
-
Add your hook to list of enabled hooks inside
enabledHooks.ts:... export const enabledHooks: Hook[] = [MyHook]; ...
-
Start or Restart the container
This project provides multiple development commands
Cloudflare workers:
npm run cf-devVercel Functions:
npm run vc-devBun
bun run bun-devDeno
deno run deno-devNode
npm run node-devTo report a bug or a feature reques use the Issues tab of the main repository with the following title:
API-PROX/<BUG|REQUEST>: <Your Title Here>
We welcome any contributions to this project! If you have any bug fixes, improvements, or new features, please feel free to create a pull request or an issue.