strapi-community / strapi-tool-dockerize

Easy add support for docker to your strapi project
MIT License
504 stars 34 forks source link

The provided middlewares.js code is causing issues during the Docker build process. #114

Closed xuqssq closed 1 month ago

xuqssq commented 1 month ago

🐛 Bug Report

If after copying the middleware.js code, the Docker build does not work properly and the thumbnails in the Strapi plugin store also fail, this could be due to some configuration errors or environment variables not being set correctly.

#0 0.324 yarn run v1.22.19
#0 0.344 $ strapi build
#0 1.442 [WARN] [@strapi/strapi]: The NODE_ENV is not set to production.  This may result in unexpected behavior.
#0 1.493 - Building build context
#0 1.493
#0 1.495 [ERROR]  There seems to be an unexpected error, try again with --debug for more information
#0 1.495
#0 1.504 ┌──────────────────────────────────────────────────────────────────────────────┐│                                                                              ││   Error: Could not load js config file /opt/app/config/middlewares.js:        ││   Cannot read properties of undefined (reading 'replace')                    ││   at loadJsFile (/opt/node_modules/@strapi/strapi/dist/core/app-configurat   ││   ion/load-config-file.js:18:13)                                             ││   at Module. loadFile (/opt/node_modules/@strapi/strapi/dist/core/app-confi   ││   guration/load-config-file.js:37:14)                                        ││   at /opt/node_modules/@strapi/strapi/dist/core/app-configuration/config-l   ││   oader.js:14:31                                                             ││   at Array. reduce (<anonymous>)                                              ││   at loadConfigDir (/opt/node_modules/@strapi/strapi/dist/core/app-configu   ││   ration/config-loader.js:12:175)                                            ││   at loadConfiguration (/opt/node_modules/@strapi/strapi/dist/core/app-con   ││   figuration/index.js:49:42)                                                 ││   at new Strapi (/opt/node_modules/@strapi/strapi/dist/Strapi.js:124:23)     ││   at Object. initFn [as default]                                              ││   (/opt/node_modules/@strapi/strapi/dist/Strapi.js:467:18)                   ││   at createBuildContext                                                      ││   (/opt/node_modules/@strapi/admin/dist/_chunks/index-sNH2VWbC.js:576:66)    ││   at Object. build                                                            ││   (/opt/node_modules/@strapi/admin/dist/_chunks/index-sNH2VWbC.js:663:21)    ││                                                                              │└──────────────────────────────────────────────────────────────────────────────┘
#0 1.530 error Command failed with exit code 1.
#0 1.530 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
failed to solve: executor failed running [yarn build]: exit code: 1

This is my modified version, it works properly and is the result I expected!

{
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "market-assets.strapi.io",
            env("CF_PUBLIC_ACCESS_URL") ? env("CF_PUBLIC_ACCESS_URL").replace(/^https?:\/\//, "") : "",
          ],
          "media-src": [
            "'self'",
            "data:",
            "blob:",
            "market-assets.strapi.io",
            env("CF_PUBLIC_ACCESS_URL") ? env("CF_PUBLIC_ACCESS_URL").replace(/^https?:\/\//, "") : "",
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },