student-v1.ts

mail@pastecode.io avatar
unknown
typescript
a year ago
868 B
4
Indexable
Never
import { APIGatewayEvent, Callback, Context } from 'aws-lambda';
import createAPI from 'lambda-api';
import database from '../shared/libs/database';
import config from '../shared/libs/config';
import coba from './v1/functions/coba';

const api = createAPI({
  version: 'v1',
  base: 'student/api/v1/',
});

/**
 * Open database connection on container start
 */
const db = database();
db.connect();
api.app('db', db);

/**
 * Close database connection on API end (cuma Local aja)
 */
api.finally(() => {
  if (config.is_local) {
    db.end();
  }
});

/**
 * ROUTES
 */
api.register((route) => {

  route.post('coba/:student_id', coba);

});

export function handler(event: APIGatewayEvent, context: Context, callback: Callback): void {
  context.callbackWaitsForEmptyEventLoop = false;

  api.run(event, context, callback);
}