From 433fee2e4be0def0d0e06634c5a2e912a1d3cd76 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Mon, 2 Dec 2024 14:42:05 +0100 Subject: [PATCH] feat: deploy api --- deno.json | 15 +++++++++++---- main.ts | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/deno.json b/deno.json index 58ec1de..cd857f5 100644 --- a/deno.json +++ b/deno.json @@ -5,7 +5,8 @@ "fe:preview": "deno run -A --node-modules-dir npm:vite preview", "fe:serve": "deno run --allow-net --allow-read jsr:@std/http@1/file-server dist/", "be:dev": "deno run --allow-all --watch --env-file server.ts", - "be:scrape": "deno run --allow-all --env-file utils/scrape/index.ts" + "be:scrape": "deno run --allow-all --env-file utils/scrape/index.ts", + "be:deploy": "deployctl deploy --env-file=.env --prod --project=naijastars-api --exclude=./node_modules --exclude=./dist --exclude=./src --exclude=./.vite main.ts" }, "compilerOptions": { "lib": ["ES2020", "DOM", "DOM.Iterable"] @@ -34,9 +35,15 @@ "vite": "npm:vite@^6.0.1" }, "deploy": { - "project": "", - "exclude": ["**/node_modules"], + "project": "c7d9d063-6f1a-4ca7-aafe-335f9ca26e97", + "exclude": [ + "./node_modules", + "./dist", + "./src", + "./.vite", + "**/node_modules" + ], "include": [], - "entrypoint": "server.ts" + "entrypoint": "main.ts" } } diff --git a/main.ts b/main.ts index e9fe009..7d62733 100644 --- a/main.ts +++ b/main.ts @@ -1 +1,40 @@ -console.log('Hello, world!'); +/// +import { Hono } from 'npm:hono'; +import { cors } from 'npm:hono/cors'; +import { cache } from 'npm:hono/cache'; + +import RepositoryHandler from './routes/repository.ts'; + +import 'jsr:@std/dotenv/load'; + +const PORT = Number(Deno.env.get('PORT')) || 8000; + +const app = new Hono(); + +/** MIDDLEWARES */ +app.use('/api/*', cors()); + +app.get( + '/api/*', + cache({ + cacheName: 'naijastars-api', + cacheControl: 'max-age=3600', + wait: true, + }) +); + +/** ROUTES */ +// Root route +app.get('/', (c) => { + return c.html( + `

Naija Stars API by ClassroomIO

` + ); +}); + +// Repository routes +app.route('/api', RepositoryHandler); + +/** START THE SERVER */ +console.log(`API server running on http://localhost:${PORT}`); + +Deno.serve({ port: PORT }, app.fetch);