forked from mito-systems/sol-mem-gen
Add API for getting latest quote
This commit is contained in:
parent
8ed2c29c44
commit
c1b0ad6ec5
18
server.ts
18
server.ts
@ -10,6 +10,22 @@ const port = parseInt(process.env.PORT || '3000', 10);
|
||||
const app = next({ dev: process.env.NODE_ENV !== 'production' });
|
||||
const handle = app.getRequestHandler();
|
||||
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
quoteService: {
|
||||
getLatestQuote: typeof getLatestQuote;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Look for a better way to use quoteService
|
||||
// Initialize the global quote service
|
||||
(global as any).quoteService = {
|
||||
getLatestQuote
|
||||
};
|
||||
|
||||
app.prepare().then(() => {
|
||||
const server = createServer(async (req, res) => {
|
||||
const parsedUrl = parse(req.url!, true);
|
||||
@ -27,5 +43,3 @@ app.prepare().then(() => {
|
||||
fetchAndCacheQuotes(); // Initial store
|
||||
setInterval(fetchAndCacheQuotes, 5 * 60 * 1000); // Update cache every 5 minutes
|
||||
});
|
||||
|
||||
export { getLatestQuote };
|
||||
|
6
src/app/api/quotes/route.ts
Normal file
6
src/app/api/quotes/route.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const quote = (global as any).quoteService.getLatestQuote();
|
||||
return NextResponse.json(quote);
|
||||
}
|
Loading…
Reference in New Issue
Block a user