File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export const applicationKey = getEnv("DISCORD_PUBLIC_KEY");
2424export const applicationId = getEnv ( "DISCORD_APP_ID" ) ;
2525export const guildId = getEnv ( "GUILD_ID" ) ;
2626export const discordToken = getEnv ( "DISCORD_HASH" ) ;
27+ export const reactibotApiKey = getEnv ( "REACTIBOT_API_KEY" , true ) ;
2728export const gitHubReadToken = getEnv ( "GH_READ_TOKEN" , true ) ;
2829export const amplitudeKey = getEnv ( "AMPLITUDE_KEY" , true ) ;
2930export const openAiKey = getEnv ( "OPENAI_KEY" , true ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010} from "./features/jobs-moderation/job-mod-helpers.js" ;
1111import { compressLineBreaks } from "./helpers/string.js" ;
1212import { constructDiscordLink } from "./helpers/discord.js" ;
13+ import { reactibotApiKey } from "./helpers/env.js" ;
1314
1415const fastify = Fastify ( { logger : true } ) ;
1516
@@ -22,6 +23,14 @@ const openApiConfig = {
2223 version : "1.0.0" ,
2324 } ,
2425 components : {
26+ securitySchemes : {
27+ apiKey : {
28+ type : "apiKey" ,
29+ name : "api-key" ,
30+ in : "header" ,
31+ } ,
32+ } ,
33+ security : [ { apiKey : [ ] } ] ,
2534 schemas : {
2635 PaginationParams : {
2736 type : "object" ,
@@ -118,6 +127,15 @@ const openApiConfig = {
118127 } ,
119128} ;
120129
130+ fastify . addHook ( "onRequest" , async ( request , reply ) => {
131+ const apiKey = request . headers [ "api-key" ] ;
132+ console . log ( "onreq" ) ;
133+ if ( apiKey !== reactibotApiKey ) {
134+ reply . code ( 401 ) . send ( { error : "Unauthorized" } ) ;
135+ return ;
136+ }
137+ } ) ;
138+
121139try {
122140 Object . entries ( openApiConfig . components . schemas ) . forEach ( ( [ k , schema ] ) => {
123141 fastify . addSchema ( { ...schema , $id : k } ) ;
You can’t perform that action at this time.
0 commit comments