Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiwilan/fastify-utils
Collection of utilities for fastify framework, built to improve DX.
https://github.com/kiwilan/fastify-utils
fastify typescript utils
Last synced: 19 days ago
JSON representation
Collection of utilities for fastify framework, built to improve DX.
- Host: GitHub
- URL: https://github.com/kiwilan/fastify-utils
- Owner: kiwilan
- License: bsd-2-clause
- Created: 2023-02-25T17:50:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-30T02:38:57.000Z (about 1 year ago)
- Last Synced: 2024-11-13T16:54:00.631Z (about 1 month ago)
- Topics: fastify, typescript, utils
- Language: TypeScript
- Homepage:
- Size: 509 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Fastify utils
Collection of utilities for fastify framework, built to improve DX.
## Installation
```bash
npm add @kiwilan/fastify-utils tsx
```Or with [pnpm](https://pnpm.js.org/):
```bash
pnpm add @kiwilan/fastify-utils tsx
```## Usage
```bash
touch setup.js
touch .eslintrc
touch .env.example
``````bash
cp .env.example .env
```### Dev setup
In `.env`:
```bash
LOG_LEVEL=debug # debug | error | fatal | info | trace | warn | silentPORT=3000
BASE_URL=localhost
HTTPS=falseCLUSTER=false
```In `setup.js`:
```javascript
import { Compiler } from "fastify-utils";Compiler.make({
// options
});
```In `package.json`:
```json
{
"scripts": {
"postinstall": "npm run config",
"config": "node setup.js",
"dev": "npm run config && NODE_ENV=development tsx watch src .env"
}
}
```In `src/index.ts`:
```typescript
import { Server } from "fastify-utils";Server.run({
// options
});
```#### Routes
In `src/routes/index.ts`:
```typescript
import { Route } from "fastify-utils";export default Route.make({
method: "GET",
url: "/",
handler: async (request, reply) => {
return { hello: "world" };
},
});
```And for `src/routes/api/posts/index.ts`:
```typescript
import { Route } from "fastify-utils";export default Route.make({
method: "GET",
url: "/api/posts", // autocomplete
handler: async (request, reply) => {
return { posts: [] };
},
});
```#### API key
In `.env`
```bash
# Could be left empty if you don't want to use it
API_KEY=
```### Build setup
In `package.json`:
```json
{
"scripts": {
"build": "rimraf build && npm run config && NODE_ENV=production tsx setup.js && npm run check:types",
"check:types": "tsc --noEmit"
}
}
```### Production setup
In `.env`:
```bash
LOG_LEVEL=error # debug | error | fatal | info | trace | warn | silentPORT=3000 # pm2 port
BASE_URL=domain.com
HTTPS=true
```In `package.json`:
```json
{
"scripts": {
"clean": "rimraf build && rimraf node_modules && pnpm install",
"start": "node build/index.mjs",
"pm2": "pm2 start --name 'fastify-utils' './build/index.mjs'"
}
}
```## Build
```bash
pnpm package
``````json
{
"dependencies": {
"@kiwilan/fastify-utils": "file:~/kiwilan-fastify-utils.tgz"
}
}
```## License
[MIT](LICENSE)