diff --git a/serverless/serverless.yaml b/serverless/serverless.yaml index bc43573..3be6f3c 100644 --- a/serverless/serverless.yaml +++ b/serverless/serverless.yaml @@ -92,4 +92,12 @@ functions: layers: - { Ref: TopicAwsNodeModulesLambdaLayer } - { Ref: TopicAwsLibsLambdaLayer } - - { Ref: TopicPrismaAwsPrismaClientLambdaLayer } \ No newline at end of file + - { Ref: TopicPrismaAwsPrismaClientLambdaLayer } + + verifyAccessPoint: + handler: src/functions/apps/handler.verifyApp + events: + - http: + path: verifyApp + method: post + cors: true \ No newline at end of file diff --git a/serverless/src/functions/apps/handler.ts b/serverless/src/functions/apps/handler.ts index d9b147f..b2e750d 100644 --- a/serverless/src/functions/apps/handler.ts +++ b/serverless/src/functions/apps/handler.ts @@ -7,8 +7,43 @@ import { BunnyCdn, BunnyCdnError, CreatePullZoneMethodArgs, + LoadFreeCertificateMethodArgs, } from '@libs/bunnyCDN'; +export const verifyApp = async ( + event: APIGatewayEvent +): Promise => { + try { + // Check the parameters and environment variables + dotenv.config(); + if (event.body === null || process.env.BUNNY_CDN_ACCESS_KEY == undefined) { + return formatJSONResponse({ + status: 422, + message: 'Required parameters were not passed.', + }); + } + + // Set up constants + const bunnyCdn = new BunnyCdn(process.env.BUNNY_CDN_ACCESS_KEY); + const hostname = JSON.parse(event.body).hostname; + + let args: LoadFreeCertificateMethodArgs = { + hostname, + }; + + await bunnyCdn.loadFreeCertificate(args); + + return formatJSONResponse({ + status: true, + }); + } catch (e) { + return formatJSONResponse({ + status: 500, + message: e, + }); + } +}; + export const submitAppInfo = async ( event: APIGatewayEvent ): Promise => { diff --git a/serverless/src/functions/apps/index.ts b/serverless/src/functions/apps/index.ts index 5db01f0..e9388fe 100644 --- a/serverless/src/functions/apps/index.ts +++ b/serverless/src/functions/apps/index.ts @@ -1,5 +1,17 @@ import { handlerPath } from '@libs/handler-resolver'; +export const verifyApp = { + handler: `${handlerPath(__dirname)}/handler.verifyApp`, + events: [ + { + http: { + method: 'post', + path: 'verifyApp', + }, + }, + ], +}; + export const submitAppInfo = { handler: `${handlerPath(__dirname)}/handler.submitAppInfo`, events: [