application.rb 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. require 'hanami/helpers'
  2. require 'hanami/assets'
  3. require_relative 'config/controller'
  4. module Web
  5. class Application < Hanami::Application
  6. configure do
  7. ##
  8. # BASIC
  9. #
  10. # Define the root path of this application.
  11. # All paths specified in this configuration are relative to path below.
  12. #
  13. root __dir__
  14. # Relative load paths where this application will recursively load the
  15. # code.
  16. #
  17. # When you add new directories, remember to add them here.
  18. #
  19. load_paths << [
  20. 'controllers',
  21. 'views'
  22. ]
  23. # Handle exceptions with HTTP statuses (true) or don't catch them (false).
  24. # Defaults to true.
  25. # See: http://www.rubydoc.info/gems/hanami-controller/#Exceptions_management
  26. #
  27. # handle_exceptions true
  28. ##
  29. # HTTP
  30. #
  31. # Routes definitions for this application
  32. # See: http://www.rubydoc.info/gems/hanami-router#Usage
  33. #
  34. routes 'config/routes'
  35. # URI scheme used by the routing system to generate absolute URLs
  36. # Defaults to "http"
  37. #
  38. # scheme 'https'
  39. # URI host used by the routing system to generate absolute URLs
  40. # Defaults to "localhost"
  41. #
  42. # host 'example.org'
  43. # URI port used by the routing system to generate absolute URLs
  44. # Argument: An object coercible to integer, defaults to 80 if the scheme
  45. # is http and 443 if it's https
  46. #
  47. # This should only be configured if app listens to non-standard ports
  48. #
  49. # port 443
  50. # Enable cookies
  51. # Argument: boolean to toggle the feature
  52. # A Hash with options
  53. #
  54. # Options:
  55. # :domain - The domain (String - nil by default, not required)
  56. # :path - Restrict cookies to a relative URI
  57. # (String - nil by default)
  58. # :max_age - Cookies expiration expressed in seconds
  59. # (Integer - nil by default)
  60. # :secure - Restrict cookies to secure connections
  61. # (Boolean - Automatically true when using HTTPS)
  62. # See #scheme and #ssl?
  63. # :httponly - Prevent JavaScript access (Boolean - true by default)
  64. #
  65. # cookies true
  66. # or
  67. # cookies max_age: 300
  68. # Enable sessions
  69. # Argument: Symbol the Rack session adapter
  70. # A Hash with options
  71. #
  72. # See: http://www.rubydoc.info/gems/rack/Rack/Session/Cookie
  73. #
  74. # sessions :cookie, secret: ENV['WEB_SESSIONS_SECRET']
  75. # Configure Rack middleware for this application
  76. #
  77. # middleware.use Rack::Protection
  78. # Default format for the requests that don't specify an HTTP_ACCEPT header
  79. # Argument: A symbol representation of a mime type, defaults to :html
  80. #
  81. # default_request_format :html
  82. # Default format for responses that don't consider the request format
  83. # Argument: A symbol representation of a mime type, defaults to :html
  84. #
  85. # default_response_format :json
  86. # HTTP Body parsers
  87. # Parse non GET responses body for a specific mime type
  88. # Argument: Symbol, which represent the format of the mime type
  89. # (only `:json` is supported)
  90. # Object, the parser
  91. #
  92. # body_parsers :json
  93. # When it's true and the router receives a non-encrypted request (http),
  94. # it redirects to the secure equivalent (https). Disabled by default.
  95. #
  96. # force_ssl true
  97. ##
  98. # TEMPLATES
  99. #
  100. # The layout to be used by all views
  101. #
  102. layout :application # It will load Web::Views::ApplicationLayout
  103. # The relative path to templates
  104. #
  105. templates 'templates'
  106. ##
  107. # ASSETS
  108. #
  109. assets do
  110. # JavaScript compressor
  111. #
  112. # Supported engines:
  113. #
  114. # * :builtin
  115. # * :uglifier
  116. # * :yui
  117. # * :closure
  118. #
  119. # See: http://hanamirb.org/guides/assets/compressors
  120. #
  121. # In order to skip JavaScript compression comment the following line
  122. # javascript_compressor :builtin
  123. # Stylesheet compressor
  124. #
  125. # Supported engines:
  126. #
  127. # * :builtin
  128. # * :yui
  129. # * :sass
  130. #
  131. # See: http://hanamirb.org/guides/assets/compressors
  132. #
  133. # In order to skip stylesheet compression comment the following line
  134. # stylesheet_compressor :builtin
  135. # Specify sources for assets
  136. #
  137. sources << [
  138. 'assets'
  139. ]
  140. end
  141. ##
  142. # SECURITY
  143. #
  144. # X-Frame-Options is a HTTP header supported by modern browsers.
  145. # It determines if a web page can or cannot be included via <frame> and
  146. # <iframe> tags by untrusted domains.
  147. #
  148. # Web applications can send this header to prevent Clickjacking attacks.
  149. #
  150. # Read more at:
  151. #
  152. # * https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
  153. # * https://www.owasp.org/index.php/Clickjacking
  154. #
  155. security.x_frame_options 'DENY'
  156. # X-Content-Type-Options prevents browsers from interpreting files as
  157. # something else than declared by the content type in the HTTP headers.
  158. #
  159. # Read more at:
  160. #
  161. # * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-Content-Type-Options
  162. # * https://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx
  163. # * https://blogs.msdn.microsoft.com/ie/2008/09/02/ie8-security-part-vi-beta-2-update
  164. #
  165. security.x_content_type_options 'nosniff'
  166. # X-XSS-Protection is a HTTP header to determine the behavior of the
  167. # browser in case an XSS attack is detected.
  168. #
  169. # Read more at:
  170. #
  171. # * https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
  172. # * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-XSS-Protection
  173. #
  174. security.x_xss_protection '1; mode=block'
  175. # Content-Security-Policy (CSP) is a HTTP header supported by modern
  176. # browsers. It determines trusted sources of execution for dynamic
  177. # contents (JavaScript) or other web related assets: stylesheets, images,
  178. # fonts, plugins, etc.
  179. #
  180. # Web applications can send this header to mitigate Cross Site Scripting
  181. # (XSS) attacks.
  182. #
  183. # The default value allows images, scripts, AJAX, fonts and CSS from the
  184. # same origin, and does not allow any other resources to load (eg object,
  185. # frame, media, etc).
  186. #
  187. # Inline JavaScript is NOT allowed. To enable it, please use:
  188. # "script-src 'unsafe-inline'".
  189. #
  190. # Content Security Policy introduction:
  191. #
  192. # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/
  193. # * https://www.owasp.org/index.php/Content_Security_Policy
  194. # * https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29
  195. #
  196. # Inline and eval JavaScript risks:
  197. #
  198. # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful
  199. # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#eval-too
  200. #
  201. # Content Security Policy usage:
  202. #
  203. # * http://content-security-policy.com/
  204. # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
  205. #
  206. # Content Security Policy references:
  207. #
  208. # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives
  209. #
  210. security.content_security_policy %{
  211. form-action 'self';
  212. frame-ancestors 'self';
  213. base-uri 'self';
  214. default-src 'none';
  215. script-src 'self';
  216. connect-src 'self';
  217. img-src 'self' https: data:;
  218. style-src 'self' 'unsafe-inline' https:;
  219. font-src 'self';
  220. object-src 'none';
  221. plugin-types application/pdf;
  222. child-src 'self';
  223. frame-src 'self';
  224. media-src 'self'
  225. }
  226. ##
  227. # FRAMEWORKS
  228. #
  229. # Configure the code that will yield each time Web::Action is included
  230. # This is useful for sharing common functionality
  231. #
  232. # See: http://www.rubydoc.info/gems/hanami-controller#Configuration
  233. controller.prepare do
  234. # include MyAuthentication # included in all the actions
  235. # before :authenticate! # run an authentication before callback
  236. end
  237. # Configure the code that will yield each time Web::View is included
  238. # This is useful for sharing common functionality
  239. #
  240. # See: http://www.rubydoc.info/gems/hanami-view#Configuration
  241. view.prepare do
  242. include Hanami::Helpers
  243. include Web::Assets::Helpers
  244. end
  245. end
  246. ##
  247. # DEVELOPMENT
  248. #
  249. configure :development do
  250. # Don't handle exceptions, render the stack trace
  251. handle_exceptions false
  252. end
  253. ##
  254. # TEST
  255. #
  256. configure :test do
  257. # Don't handle exceptions, render the stack trace
  258. handle_exceptions false
  259. end
  260. ##
  261. # PRODUCTION
  262. #
  263. configure :production do
  264. # scheme 'https'
  265. # host 'example.org'
  266. # port 443
  267. assets do
  268. # Don't compile static assets in production mode (eg. Sass, ES6)
  269. #
  270. # See: http://www.rubydoc.info/gems/hanami-assets#Configuration
  271. compile false
  272. # Use fingerprint file name for asset paths
  273. #
  274. # See: http://hanamirb.org/guides/assets/overview
  275. fingerprint false
  276. # Content Delivery Network (CDN)
  277. #
  278. # See: http://hanamirb.org/guides/assets/content-delivery-network
  279. #
  280. # scheme 'https'
  281. # host 'cdn.example.org'
  282. # port 443
  283. # Subresource Integrity
  284. #
  285. # See: http://hanamirb.org/guides/assets/content-delivery-network/#subresource-integrity
  286. subresource_integrity :sha256
  287. end
  288. end
  289. end
  290. end