cors.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Config source: https://git.io/JfefC
  3. *
  4. * Feel free to let us know via PR, if you find something broken in this config
  5. * file.
  6. */
  7. import type { CorsConfig } from '@ioc:Adonis/Core/Cors'
  8. const corsConfig: CorsConfig = {
  9. /*
  10. |--------------------------------------------------------------------------
  11. | Enabled
  12. |--------------------------------------------------------------------------
  13. |
  14. | A boolean to enable or disable CORS integration from your AdonisJs
  15. | application.
  16. |
  17. | Setting the value to `true` will enable the CORS for all HTTP request. However,
  18. | you can define a function to enable/disable it on per request basis as well.
  19. |
  20. */
  21. enabled: true,
  22. // You can also use a function that return true or false.
  23. // enabled: (request) => request.url().startsWith('/api')
  24. /*
  25. |--------------------------------------------------------------------------
  26. | Origin
  27. |--------------------------------------------------------------------------
  28. |
  29. | Set a list of origins to be allowed for `Access-Control-Allow-Origin`.
  30. | The value can be one of the following:
  31. |
  32. | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
  33. |
  34. | Boolean (true) - Allow current request origin.
  35. | Boolean (false) - Disallow all.
  36. | String - Comma separated list of allowed origins.
  37. | Array - An array of allowed origins.
  38. | String (*) - A wildcard (*) to allow all request origins.
  39. | Function - Receives the current origin string and should return
  40. | one of the above values.
  41. |
  42. */
  43. origin: true,
  44. /*
  45. |--------------------------------------------------------------------------
  46. | Methods
  47. |--------------------------------------------------------------------------
  48. |
  49. | An array of allowed HTTP methods for CORS. The `Access-Control-Request-Method`
  50. | is checked against the following list.
  51. |
  52. | Following is the list of default methods. Feel free to add more.
  53. */
  54. methods: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'],
  55. /*
  56. |--------------------------------------------------------------------------
  57. | Headers
  58. |--------------------------------------------------------------------------
  59. |
  60. | List of headers to be allowed for `Access-Control-Allow-Headers` header.
  61. | The value can be one of the following:
  62. |
  63. | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers
  64. |
  65. | Boolean(true) - Allow all headers mentioned in `Access-Control-Request-Headers`.
  66. | Boolean(false) - Disallow all headers.
  67. | String - Comma separated list of allowed headers.
  68. | Array - An array of allowed headers.
  69. | Function - Receives the current header and should return one of the above values.
  70. |
  71. */
  72. headers: true,
  73. /*
  74. |--------------------------------------------------------------------------
  75. | Expose Headers
  76. |--------------------------------------------------------------------------
  77. |
  78. | A list of headers to be exposed by setting `Access-Control-Expose-Headers`.
  79. | header. By default following 6 simple response headers are exposed.
  80. |
  81. | Cache-Control
  82. | Content-Language
  83. | Content-Type
  84. | Expires
  85. | Last-Modified
  86. | Pragma
  87. |
  88. | In order to add more headers, simply define them inside the following array.
  89. |
  90. | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
  91. |
  92. */
  93. exposeHeaders: [
  94. 'cache-control',
  95. 'content-language',
  96. 'content-type',
  97. 'expires',
  98. 'last-modified',
  99. 'pragma'
  100. ],
  101. /*
  102. |--------------------------------------------------------------------------
  103. | Credentials
  104. |--------------------------------------------------------------------------
  105. |
  106. | Toggle `Access-Control-Allow-Credentials` header. If value is set to `true`,
  107. | then header will be set, otherwise not.
  108. |
  109. | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
  110. |
  111. */
  112. credentials: true,
  113. /*
  114. |--------------------------------------------------------------------------
  115. | MaxAge
  116. |--------------------------------------------------------------------------
  117. |
  118. | Define `Access-Control-Max-Age` header in seconds.
  119. | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
  120. |
  121. */
  122. maxAge: 90
  123. }
  124. export default corsConfig