This repo contains the code for a hono based API server with the most usual addtional protection and control middlewares. The code is fully functional for testing on local environments and for deployments in environments supporting node:fs. For other deployments (such as Cloudflare workers) it is necessary to add specfific code to manage AAPI keyes or other data necessary for the middlewares, as instructed in code comments.
clone the repo backend-template and run `npm install`
edit .env and package.json
macOS: ipconfig getifaddr en0
Linux: hostname -I
Windows: ipconfig
macOS:
brew install mkcert
mkcert -install
Windows:
winget install FiloSottile.mkcert
mkcert -install
Linux (Ubuntu/Debian):
sudo apt install mkcert
mkcert -install
IMPORTANT: The following 2 lines must be executed each time when the localhost IP changes
cd <project-root-directory>
mkcert localhost 127.0.0.1 <localhost_IP>
mv <generated-file>.pem cert.pem
mv <generated-file-key>.pem key.pem
npx tsc --init
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["node"],
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"outDir": "dist"
},
"include": ["*.ts", "src/**/*.ts", "scripts/**/*.ts"]
}
"name": "<whatever-name-you-want-for-your-server>",
"version": "1.0.0",
"type": "module", // --> important
"private": true,
npm run dev (local)
npm run start (prod or simprod)
npx tsx scripts/generate-key.ts
raw key to be used in api request in header: Authorization: Bearer <raw_api_key>
has key to added to keystore.json together with the scopes granted to that api key