Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/radyai/onelink-service
This is the backend and api for onelink
https://github.com/radyai/onelink-service
fastify firebase typescript
Last synced: about 2 months ago
JSON representation
This is the backend and api for onelink
- Host: GitHub
- URL: https://github.com/radyai/onelink-service
- Owner: RadyaI
- Created: 2024-07-20T04:31:49.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-21T12:33:31.000Z (5 months ago)
- Last Synced: 2024-10-12T02:42:08.408Z (2 months ago)
- Topics: fastify, firebase, typescript
- Language: TypeScript
- Homepage: https://onelink-api.radya.fun
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fastify + Tyscript
## Pertama
Install typescript dan ts-node menggunakan```bash
npm i typescript ts-node
```## Kedua
Buat file bernama tsconfig.json yang berisi```json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./api",
"strict": true,
"esModuleInterop": true
},
"include": ["api/**/*"],
"exclude": ["node_modules"]
}
```atau kamu bisa lihat di dokumentasi typescript sendiri disini
[https://www.typescriptlang.org/docs/handbook/tsconfig-json.html](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
## Ketiga
Ubah semua file ts nya menjadi js sebelum kamu run stepnya```bash
npx tscnpm run start
```oh iya pastiin juga bagian script pada package.json seperti ini
```json
"scripts": {
"build": "npx tsc",
"start": "node dist/index.js",
"dev": "ts-node api/index.ts",
"vercel-build": "npm run build"
}
```
## Keempat (opsional)
Pada file index.ts bisa kamu ubah seperti ini```typescript
import Fastify from 'fastify';const app = Fastify({
logger: true,
});const start = async () => {
try {
await app.listen({ port: 3000 });
console.log(`Server is running at http://localhost:3000`);
} catch (err) {
app.log.error(err);
process.exit(1);
}
};start();
export default async function handler(req: any, reply: any) {
await app.ready();
app.server.emit('request', req, reply);
}
```atau kamu bisa lihat langsung pada dokumentasi fastify sendiri disini
[https://fastify.dev/](https://fastify.dev/)## Kalo pake vercel
Ubah file vercel.json menjadi seperti ini```json
{
"builds": [
{
"src": "api/index.ts",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/api/index.ts"
}
]
}
```
Made by [Radya](https://radya.fun)