# This is the UPWARD specification file for the Venia storefront.
# It is used by an UPWARD server implementation, such as upward-js and
# upward-php, to describe how the server responds to requests.
# See: https://pwastudio.io/technologies/upward/

# The root properties of an UPWARD spec file are part of a global context
# that includes request and environment data.
# These properties are available to other properties and are ultimately
# populated with Resolvers.

# The root 'status', 'headers', and 'body' properties are required properties
# in an UPWARD spec file.
# An UPWARD server uses the resolved values of these properties to create an
# HTTP response to the client.
# In this file, these properties get their values from a top-level
# 'response' object, which is a recommended and best practice approach.
veniaResponse:
  resolver: conditional
  when:
    # Requests to graphql/rest endpoints, the media library, and cache are
    # handled by the top-level 'veniaProxy' object, which is a ProxyResolver
    # that passes the request through to the backing Magento server.
    - matches: request.url.pathname
      pattern: "^/(graphql|rest|media|pub)(/|$)"
      use: veniaProxy
    - matches: request.url.pathname
      pattern: '^/(robots\.txt|favicon\.ico|manifest\.json)'
      use: staticFromRoot
    - matches: fileExtension
      pattern: "(js|json|png|jpg|jpeg|gif|svg|ico|css|txt|eot|otf|ttf|woff|woff2)"
      use: veniaStatic
  default: veniaAppShell

staticFromRoot:
  inline:
    status: 200
    headers:
      resolver: inline
      inline:
        content-type: contentTypeFromExtension
        cache-control:
          when:
              - matches: env.NODE_ENV
                pattern: 'production'
                use:
                  inline: public, max-age=604800
          default:
              inline: no-cache, no-store, must-revalidate
    body:
      resolver: file
      parse:
        inline: text
      encoding:
        inline: binary
      file:
        resolver: template
        engine: mustache
        provide:
          filename: request.url.pathname
        template:
          resolver: inline
          inline: "./cenia-static/{{ filename }}"

veniaStaticIncludes:
  resolver: directory
  directory:
    resolver: inline
    inline: "./cenia-static"

status: veniaResponse.status
headers: veniaResponse.headers
body: veniaResponse.body
