Skip to content

Commit

Permalink
feat: deploy api
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi-best committed Dec 2, 2024
1 parent f7c5af2 commit 433fee2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
15 changes: 11 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"
}
}
41 changes: 40 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
console.log('Hello, world!');
/// <reference lib="deno.ns" />
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(
`<h4>Naija Stars API by <a href="https://classroomio.com">ClassroomIO</a></h4>`
);
});

// Repository routes
app.route('/api', RepositoryHandler);

/** START THE SERVER */
console.log(`API server running on http://localhost:${PORT}`);

Deno.serve({ port: PORT }, app.fetch);

0 comments on commit 433fee2

Please sign in to comment.