handle cors

This commit is contained in:
2023-06-15 00:13:58 -04:00
parent ae09a60637
commit 8b4a5ec91b
3 changed files with 40 additions and 0 deletions
+14
View File
@@ -7,8 +7,10 @@ await ingestOptions(sourceDataDir);
*/
import fastify from 'fastify'
import cors from '@fastify/cors'
const server = fastify()
await server.register(cors, {});
server.get('/ping', async (request, reply) => {
return 'pong\n'
@@ -18,6 +20,18 @@ server.get('/option_quotes/underlyings', async (request, reply) => {
const underlyings = (await sql`SELECT DISTINCT "underlying" FROM "option_quote";`).map(x=>x.underlying);
reply.status(200).send(underlyings);
})
server.get<{
Params: {underlying:string},
}>('/option_quotes/:underlying/quote_dates', async (request, reply) => {
const options_quotes = (await sql`
SELECT DISTINCT "quote_date"
FROM "option_quote"
WHERE
"underlying" = ${request.params.underlying}
ORDER BY "quote_date";`
).map(x=>x.quote_date);
reply.status(200).send(options_quotes);
})
server.get<{
Params: {underlying:string, quote_date:string},
}>('/option_quotes/:underlying/:quote_date', async (request, reply) => {