Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phtmgt opened this issue Mar 31, 2021 · 15 comments
Open

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

phtmgt opened this issue Mar 31, 2021 · 15 comments

Comments

@phtmgt
Copy link

phtmgt commented Mar 31, 2021

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
Copy link

i'm also facing this issue ....

@phtmgt
Copy link
Author

phtmgt commented May 23, 2021

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

@sirugh
Copy link

sirugh commented May 23, 2021

@magento export issue to JIRA project PWA as Bug

@github-jira-sync-bot
Copy link

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

2 similar comments
@github-jira-sync-bot
Copy link

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

@github-jira-sync-bot
Copy link

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

@sirugh
Copy link

sirugh commented May 24, 2021

@jerschipper
Copy link

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
Copy link
Author

phtmgt commented Jun 2, 2021

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
Copy link

@plamenh,

What was the error?

@slemos
Copy link

slemos commented Nov 22, 2021

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
Copy link
Author

phtmgt commented Nov 23, 2021

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

@phtmgt
Copy link
Author

phtmgt commented Nov 23, 2021

@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
Copy link

0m3r commented Jun 17, 2022

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
Copy link
Member

fastcgi_param MAGENTO_BACKEND_URL = "example.com".

It should be like this

fastcgi_param MAGENTO_BACKEND_URL "example.com";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants