-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7c5af2
commit 433fee2
Showing
2 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |