How to use the middy/middlewares.cors function in middy

To help you get started, we’ve selected a few middy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github josephluck / internote / services / notes / update.ts View on Github external
export const validator = validateRequestBody({
  noteId: [],
  userId: [],
  content: [required], // TODO: validate slate schema
  title: [required, isString],
  tags: [required, isArray(v => typeof v === "string")],
  dateUpdated: [],
  overwrite: []
});

export const handler = middy(update)
  .use(jsonBodyParser())
  .use(validator)
  .use(encodeResponse())
  .use(jsonErrorHandler())
  .use(cors());
github josephluck / internote / services / export / markdown.ts View on Github external
ACL: "public-read"
  }).promise();

  const src = `https://s3-${process.env.REGION}.amazonaws.com/${process.env.EXPORT_BUCKET}/${S3UploadPath}`;

  const response: ExportResponseDTO = { src };

  return callback(null, success(response));
};

export const handler = middy(markdown)
  .use(jsonBodyParser())
  .use(validator)
  .use(encodeResponse())
  .use(jsonErrorHandler())
  .use(cors());
github faultline / faultline / src / handlers / projectsDelete.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ProjectsDeleteHandler(aws))
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github faultline / faultline / src / handlers / occurrencesList.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new OccurrencesListHandler(aws))
        .use(httpHeaderNormalizer())
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github josephluck / internote / services / notes / list.ts View on Github external
import { encodeResponse } from "@internote/lib/middlewares";
import { success } from "@internote/lib/responses";
import { getUserIdentityId } from "@internote/lib/user";
import { GetHandler } from "@internote/lib/types";
import { listNotesByUserId } from "./db/queries";

const list: GetHandler = async (event, _ctx, callback) => {
  const userId = getUserIdentityId(event);
  const notes = await listNotesByUserId(userId);
  return callback(null, success(notes));
};

export const handler = middy(list)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());
github josephluck / internote / services / snippets / create.ts View on Github external
event,
  _ctx,
  callback
) => {
  const userId = getUserIdentityId(event);
  const noteId = uuid();
  const note = await createSnippet(noteId, userId, event.body);
  return callback(null, success(note));
};

export const handler = middy(create)
  .use(jsonBodyParser())
  .use(validator)
  .use(encodeResponse())
  .use(jsonErrorHandler())
  .use(cors());
github faultline / faultline / src / handlers / occurrencesGet.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new OccurrencesGetHandler(aws))
        .use(httpHeaderNormalizer())
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github faultline / faultline / src / handlers / errorsPatch.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ErrorsPatchHandler(aws))
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github josephluck / internote / services / notes / delete.ts View on Github external
const del33t: DeleteHandler<{ noteId: string }> = async (
  event,
  _ctx,
  callback
) => {
  const { noteId } = event.pathParameters;
  const userId = getUserIdentityId(event);
  await deleteNoteById(noteId, userId);
  return callback(null, success({}));
};

export const handler = middy(del33t)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());
github josephluck / internote / services / notes / tags.ts View on Github external
const list: GetHandler = async (event, _ctx, callback) => {
  const userId = getUserIdentityId(event);
  const notes = await listNotesByUserId(userId);
  const allTags = notes.reduce(
    (ts, note) => [...ts, ...note.tags],
    [] as string[]
  );
  const dedupedTags = [...new Set(allTags)];
  return callback(null, success(dedupedTags));
};

export const handler = middy(list)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());