Menu
Menu Sheet Overlay
Search
Search Sheet

      Mobify Progressive Web SDK Docs

      SSR Configuration

      Key parts of the setup of the SSR server are controlled by configuration options in the mobify object, defined at the top level of the project's package.json file. Here's an example (with other parts of package.json omitted for clarity):

      {
        "name": "progressive-web-scaffold",
        "mobify": {
          "pageNotFoundURL": "/page-not-found",
          "ssrEnabled": true,
          "ssrOnly": [
            "ssr.js",
            "ssr.js.map"
          ],
          "ssrShared": [
            "main.css",
            "static/ico/favicon.ico",
            "static/robots.txt",
            "**/*.js",
            "**/*.js.map"
          ],
          "ssrParameters": {
            "proxyProtocol1": "https",
            "proxyHost1": "www.merlinspotions.com",
            "proxyPath1": "base"
          }
        }
      }

      The key values are as follows:

      pageNotFoundURL #

      The route ("path" part of the URL) that the UPWA uses to render a "page not found" page. If the SSR server receives a request for a route that the UPWA does not recognize (see the routes option for the SSRServer class)), and which is not handled by the requestHook, then it will request the UPWA to render the route defined in the pageNotFoundURL.

      ssrEnabled #

      This boolean flag should be set to true for a UPWA project. If the project is based on the Mobify platform scaffold, then setting this to true enables building of the SSR-related parts of the project. The value also marks any bundles pushed to Mobify Cloud as containing SSR files. If this value is not true, deploying those bundles will not create SSR servers.

      ssrOnly and ssrShared #

      For efficiency, when a bundle is pushed to Mobify Cloud, not all the files in that bundle are packaged up and made available to the SSR server in remote mode. For example, large image files aren't used in server-side rendering, and including them as part ofa remote mode SSR server slows down bundle deployment and SSR rendering.

      The ssrOnly and ssrShared properties are lists of bundle files, relative to the build directory (the output directory for webpack or other build tools) that define which bundle files are made available to the SSR server when it's running in remote mode. They are lists of globbing patterns where * is a wildcard matching zero or more of any character.

      The ssrOnly list defines which files are only part of the SSR server, and should not be made available under the /mobify/bundle/ path. Typically this would include the ssr.js file that instantiates the SSRServer class.

      The ssrShared list defines which files are made available to the SSR Server and are also available available under the /mobify/bundle/ path. Typically this list will include:

      • The UPWA JavaScript files: main.js, vendor.js and worker.js. The example above includes them with .js* extensions so that .map files will also be available to the SSR Server, for more meaningful stack traces in the event of errors.

      • Any extra JS files such as webpack chunks (for example, product-list*.js*) that may be loaded by the UPWA when running server-side.

      • Any bundle files that the UPWA might need to load from the file system. For example, see the requestHook implemented in the SSR Server example which uses response.sendFile to load bundle files. If a file was not listed in ssrShared, it would not be present when the SSR Server is running in remote mode, and the file load would fail.

      ssrParameters #

      This section contains additional parameters that configure SSR server behaviour. The proxy-related values are explained in the section on proxying.

      Feedback

      Was this page helpful?