magento / magento2-upward-connector

Magento module for routing front-end requests to UPWARD-PHP
Open Software License 3.0
24 stars 27 forks source link

{"error":"No definition for env.MAGENTO_BACKEND_URL"} #33

Open phtmgt opened 3 years ago

phtmgt commented 3 years ago

This happens with the following upward.yml, generated by my (properly functioning in watch mode) instance:

veniaResponse:
  resolver: conditional
  when:
    - matches: request.url.pathname
      pattern: ^/(graphql|rest|media)(/|$)
      use: veniaProxy
    - matches: request.url.pathname
      pattern: ^/(robots\.txt|favicon\.ico|manifest\.json)
      use: staticFromRoot
    - matches: fileExtension
      pattern: (js|json|png|jpg|gif|svg|ico|css|txt)
      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: './venia-static/{{ filename }}'
contentTypeFromExtension:
  when:
    - matches: fileExtension
      pattern: ^ico$
      use:
        inline: image/x-icon
    - matches: fileExtension
      pattern: ^txt$
      use:
        inline: text/plain
    - matches: fileExtension
      pattern: ^json$
      use:
        inline: application/json
  default:
    inline: text/html
fileExtension:
  resolver: conditional
  when:
    - matches: request.url.pathname
      pattern: \.(.*)$
      use: $match.$1
  default:
    inline: ''
veniaProxy:
  resolver: proxy
  target: env.MAGENTO_BACKEND_URL
  ignoreSSLErrors:
    when:
      - matches: env.NODE_ENV
        pattern: production
        use:
          inline: false
    default:
      inline: true
veniaAppShell:
  resolver: inline
  inline:
    status:
      resolver: inline
      inline: 200
    headers:
      resolver: inline
      inline:
        content-type:
          inline: text/html
        content-security-policy: veniaSecurityHeaders.content-security-policy
        strict-transport-security: veniaSecurityHeaders.strict-transport-security
        x-content-type-options: veniaSecurityHeaders.x-content-type-options
        x-frame-options: veniaSecurityHeaders.x-frame-options
        x-xss-protection: veniaSecurityHeaders.x-xss-protection
    body:
      resolver: file
      file:
        resolver: inline
        inline: ./index.html
veniaStatic:
  resolver: directory
  directory:
    resolver: inline
    inline: .
veniaStaticIncludes:
  resolver: directory
  directory:
    resolver: inline
    inline: ./venia-static
veniaSecurityHeaders:
  resolver: inline
  inline:
    content-security-policy:
      resolver: template
      engine: mustache
      provide:
        backend: env.MAGENTO_BACKEND_URL
      template:
        resolver: conditional
        when:
          - matches: env.NODE_ENV
            pattern: development
            use:
              inline: ''
        default:
          inline: >-
            script-src http: https: {{ backend }}; style-src 'self' blob: https:
            'unsafe-inline' {{ backend }}; img-src data: http: https:;
            object-src 'none'; base-uri 'none'; child-src 'self'; font-src
            'self' fonts.gstatic.com; frame-src assets.braintreegateway.com
            *.youtube.com *.youtu.be *.vimeo.com
    strict-transport-security:
      inline: max-age=31536000
    x-content-type-options:
      inline: nosniff
    x-frame-options:
      inline: SAMEORIGIN
    x-xss-protection:
      inline: 1; mode=block
status: veniaResponse.status
headers: veniaResponse.headers
body: veniaResponse.body

On the other hand, this random upward.yml I found on stack exchange functions partially (opens homepage, the other pages are not working):

veniaResponse:
  resolver: conditional
  when:
    - matches: request.url.pathname
      pattern: ^/(graphql|rest|media)(/|$)
      use: veniaProxy
    - matches: request.url.pathname
      pattern: ^/(robots\.txt|favicon\.ico|manifest\.json)
      use: staticFromRoot
    - matches: fileExtension
      pattern: (js|json|png|svg|ico|css|txt)
      use: veniaStatic
  default: veniaAppShell
staticFromRoot:
  inline:
    status: 200
    headers:
      resolver: inline
      inline:
        content-type: contentTypeFromExtension
    body:
      resolver: file
      parse:
        inline: text
      encoding:
        inline: binary
      file:
        resolver: template
        engine: mustache
        provide:
          filename: request.url.pathname
        template:
          resolver: inline
          inline: './venia-static/{{ filename }}'
contentTypeFromExtension:
  when:
    - matches: fileExtension
      pattern: ^ico$
      use:
        inline: image/x-icon
    - matches: fileExtension
      pattern: ^txt$
      use:
        inline: text/plain
    - matches: fileExtension
      pattern: ^json$
      use:
        inline: application/json
  default:
    inline: text/html
fileExtension:
  resolver: conditional
  when:
    - matches: request.url.pathname
      pattern: \.(.*)$
      use: $match.$1
  default:
    inline: ''
veniaProxy:
  resolver: proxy
  target: env.MAGENTO_BACKEND_URL
  ignoreSSLErrors:
    when:
      - matches: env.NODE_ENV
        pattern: production
        use:
          inline: false
    default:
      inline: true
veniaAppShell:
  resolver: inline
  inline:
    status:
      resolver: inline
      inline: 200
    headers:
      resolver: inline
      inline:
        content-type:
          inline: text/html
    body:
      resolver: file
      file:
        resolver: inline
        inline: ./index.html
veniaStatic:
  resolver: directory
  directory:
    resolver: inline
    inline: .
veniaTemplateIncludes:
  resolver: directory
  directory:
    resolver: inline
    inline: ./templates
veniaStaticIncludes:
  resolver: directory
  directory:
    resolver: inline
    inline: ./venia-static
status: veniaResponse.status
headers: veniaResponse.headers
body: veniaResponse.body

The fact the second one works makes me think the issue is not related to the env.MAGENTO_BACKEND_URL value, but I am no expert. Something related to the security headers maybe? My backend instance does not have a proper ssl certificate, might this be the issue?

prabhakaran-wac commented 3 years ago

i'm also facing this issue ....

phtmgt commented 3 years ago

@prabhakaran-wac I gave up on this long time ago. No one from the community ever answered. I am now using upwardjs.

sirugh commented 3 years ago

@magento export issue to JIRA project PWA as Bug

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. GitHub repo magento/magento2-upward-connector is not supported in JIRA project PWA and type Bug.

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. GitHub repo magento/magento2-upward-connector is not supported in JIRA project PWA and type Bug.

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. GitHub repo magento/magento2-upward-connector is not supported in JIRA project PWA and type Bug.

sirugh commented 3 years ago

Was this thread any help: https://magentocommeng.slack.com/archives/C71HNKYS2/p1621105708128600

jerschipper commented 3 years ago

So, i've runned into this problem. What simple solution is, is to add an fastcgi_param in nginx.

For example look in the nginx.conf.sample file from the main magento2 repository and search for `# PHP entry point for main application location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check).php$ { try_files $uri =404; fastcgi_pass fastcgi_backend; fastcgi_buffers 1024 4k;

fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param  PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;

fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;

}`

in this block you could add a fastcgi_param MAGENTO_BACKEND_URL = "example.com". Restart nginx after this and it should work.

Unfortunately, the hosting provider we used had a custom nginx config that we could't update. So we had to make some modifications in the logic from this module. Would not recommend to do that, because a simple fastcgi_param should fix this problem ;).

phtmgt commented 3 years ago

Was this thread any help: https://magentocommeng.slack.com/archives/C71HNKYS2/p1621105708128600

This thread mentions a fix which I already tried. For me it is no good, as this is some static tweaked upward.yml file that introduces other issues.

jerschipper commented 3 years ago

@plamenh,

What was the error?

slemos commented 2 years ago

I'm facing the same error. Using Apache2 and generated upward.yml from running 'yarn build:dev'. Home page response: {"error":"No definition for env.MAGENTO_BACKEND_URL"}

I've tried to set the env in virtualhost definition, but no luck.

phtmgt commented 2 years ago

@slemos don't bother with this. just spin up an upwardjs server and call it a day.

phtmgt commented 2 years ago

@jerschipper The error was the same as the one @slemos received - {"error":"No definition for env.MAGENTO_BACKEND_URL"}. I tried the fastcgi params in the very beginning ( and all kinds of other params and env variables that I could think of, e.g. NODE_ENV, bash, etc.)

0m3r commented 2 years ago

you can use my custom module https://github.com/swissup/module-upward-connector it added a custom config options Screenshot from 2022-06-17 13-57-23 fastcgi_param don't need anymore

pjayramkumar commented 1 year ago

fastcgi_param MAGENTO_BACKEND_URL = "example.com".

It should be like this

fastcgi_param MAGENTO_BACKEND_URL "example.com";