import * as cdk from '@aws-cdk/core';
import { HttpApi } from '@aws-cdk/aws-apigatewayv2';
import { CfnOutput } from '@aws-cdk/core';

import { route } from '@jet-cdk/afterburner/apigatewayv2';
import nodejs from '@jet-cdk/afterburner/apigatewayv2/prefab-tags/nodejs';

export class ApiStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const api = new HttpApi(this, 'api');

    route(api, {
      '/my': { GET: nodejs`lib/my-function.ts` },
    });

    new CfnOutput(this, 'apiUrl', { value: api.url ?? '' });
  }
}
