index.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Type definitions for cors 2.8
  2. // Project: https://github.com/expressjs/cors/
  3. // Definitions by: Alan Plum <https://github.com/pluma>
  4. // Gaurav Sharma <https://github.com/gtpan77>
  5. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  6. // TypeScript Version: 2.3
  7. import express = require('express');
  8. type CustomOrigin = (
  9. requestOrigin: string | undefined,
  10. callback: (err: Error | null, allow?: boolean) => void
  11. ) => void;
  12. declare namespace e {
  13. interface CorsOptions {
  14. /**
  15. * @default '*''
  16. */
  17. origin?: boolean | string | RegExp | (string | RegExp)[] | CustomOrigin;
  18. /**
  19. * @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
  20. */
  21. methods?: string | string[];
  22. allowedHeaders?: string | string[];
  23. exposedHeaders?: string | string[];
  24. credentials?: boolean;
  25. maxAge?: number;
  26. /**
  27. * @default false
  28. */
  29. preflightContinue?: boolean;
  30. /**
  31. * @default 204
  32. */
  33. optionsSuccessStatus?: number;
  34. }
  35. type CorsOptionsDelegate = (
  36. req: express.Request,
  37. callback: (err: Error | null, options?: CorsOptions) => void
  38. ) => void;
  39. }
  40. declare function e(
  41. options?: e.CorsOptions | e.CorsOptionsDelegate
  42. ): express.RequestHandler;
  43. export = e;