handle cors

master
Avraham Sakal 2 years ago
parent ae09a60637
commit 8b4a5ec91b

@ -5,6 +5,7 @@
"build": "node build.mjs" "build": "node build.mjs"
}, },
"dependencies": { "dependencies": {
"@fastify/cors": "^8.3.0",
"csv-parse": "^5.4.0", "csv-parse": "^5.4.0",
"fastify": "^4.18.0", "fastify": "^4.18.0",
"postgres": "^3.3.5" "postgres": "^3.3.5"

@ -7,8 +7,10 @@ await ingestOptions(sourceDataDir);
*/ */
import fastify from 'fastify' import fastify from 'fastify'
import cors from '@fastify/cors'
const server = fastify() const server = fastify()
await server.register(cors, {});
server.get('/ping', async (request, reply) => { server.get('/ping', async (request, reply) => {
return 'pong\n' 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); const underlyings = (await sql`SELECT DISTINCT "underlying" FROM "option_quote";`).map(x=>x.underlying);
reply.status(200).send(underlyings); 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<{ server.get<{
Params: {underlying:string, quote_date:string}, Params: {underlying:string, quote_date:string},
}>('/option_quotes/:underlying/:quote_date', async (request, reply) => { }>('/option_quotes/:underlying/:quote_date', async (request, reply) => {

@ -121,6 +121,14 @@
ajv-formats "^2.1.1" ajv-formats "^2.1.1"
fast-uri "^2.0.0" fast-uri "^2.0.0"
"@fastify/cors@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@fastify/cors/-/cors-8.3.0.tgz#f03d745731b770793a1a15344da7220ca0d19619"
integrity sha512-oj9xkka2Tg0MrwuKhsSUumcAkfp2YCnKxmFEusi01pjk1YrdDsuSYTHXEelWNW+ilSy/ApZq0c2SvhKrLX0H1g==
dependencies:
fastify-plugin "^4.0.0"
mnemonist "0.39.5"
"@fastify/deepmerge@^1.0.0": "@fastify/deepmerge@^1.0.0":
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/@fastify/deepmerge/-/deepmerge-1.3.0.tgz#8116858108f0c7d9fd460d05a7d637a13fe3239a" resolved "https://registry.yarnpkg.com/@fastify/deepmerge/-/deepmerge-1.3.0.tgz#8116858108f0c7d9fd460d05a7d637a13fe3239a"
@ -303,6 +311,11 @@ fast-uri@^2.0.0, fast-uri@^2.1.0:
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-2.2.0.tgz#519a0f849bef714aad10e9753d69d8f758f7445a" resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-2.2.0.tgz#519a0f849bef714aad10e9753d69d8f758f7445a"
integrity sha512-cIusKBIt/R/oI6z/1nyfe2FvGKVTohVRfvkOhvx0nCEW+xf5NoCXjAHcWp93uOUBchzYcsvPlrapAdX1uW+YGg== integrity sha512-cIusKBIt/R/oI6z/1nyfe2FvGKVTohVRfvkOhvx0nCEW+xf5NoCXjAHcWp93uOUBchzYcsvPlrapAdX1uW+YGg==
fastify-plugin@^4.0.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/fastify-plugin/-/fastify-plugin-4.5.0.tgz#8b853923a0bba6ab6921bb8f35b81224e6988d91"
integrity sha512-79ak0JxddO0utAXAQ5ccKhvs6vX2MGyHHMMsmZkBANrq3hXc1CHzvNPHOcvTsVMEPl5I+NT+RO4YKMGehOfSIg==
fastify@^4.18.0: fastify@^4.18.0:
version "4.18.0" version "4.18.0"
resolved "https://registry.yarnpkg.com/fastify/-/fastify-4.18.0.tgz#d369630ac1dcedb218e6a933380ed81447c3af11" resolved "https://registry.yarnpkg.com/fastify/-/fastify-4.18.0.tgz#d369630ac1dcedb218e6a933380ed81447c3af11"
@ -377,11 +390,23 @@ lru-cache@^6.0.0:
dependencies: dependencies:
yallist "^4.0.0" yallist "^4.0.0"
mnemonist@0.39.5:
version "0.39.5"
resolved "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.39.5.tgz#5850d9b30d1b2bc57cc8787e5caa40f6c3420477"
integrity sha512-FPUtkhtJ0efmEFGpU14x7jGbTB+s18LrzRL2KgoWz9YvcY3cPomz8tih01GbHwnGk/OmkOKfqd/RAQoc8Lm7DQ==
dependencies:
obliterator "^2.0.1"
ms@2.1.2: ms@2.1.2:
version "2.1.2" version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
obliterator@^2.0.1:
version "2.0.4"
resolved "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.4.tgz#fa650e019b2d075d745e44f1effeb13a2adbe816"
integrity sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==
on-exit-leak-free@^2.1.0: on-exit-leak-free@^2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz#5c703c968f7e7f851885f6459bf8a8a57edc9cc4" resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz#5c703c968f7e7f851885f6459bf8a8a57edc9cc4"

Loading…
Cancel
Save