unfoldingWord / gateway-translate

A tool for editing and translating text in USFM markup
MIT License
2 stars 3 forks source link

Send feedback in menu does not work #111

Closed superdav42 closed 1 year ago

superdav42 commented 1 year ago

It always timesout.

mandolyte commented 1 year ago

All three gateway apps use the same code. I just tested gateway-edit and -admin and it work in both. So only gateway-translate is having this problem.

mandolyte commented 1 year ago

@superdav42 seems to work ok running locally (once you provide the .env var values).

I changed the timeout to 10s and it still claims it is timing out. But the console shows this: image

So now I am wondering if the problem is the "NonSSRWrapper" that I added early on because of other issues we were having (don't recall them at the moment).

superdav42 commented 1 year ago

So now I am wondering if the problem is the "NonSSRWrapper" that I added early on because of other issues we were having (don't recall them at the moment).

I wouldn't expect SSR to be related. It seems when I looked that nothing was setup at /api/feedback to respond to the request. Of course I wouldn't expect it to timeout either. So I don't know.

mandolyte commented 1 year ago

Current working hypothesis, notes, and next steps.

  1. Works locally just fine, but not when deployed
  2. I believe that the NonSSRWrapper (used to solve another issue) is preventing the "server side" code from being generated. Thus the /api/feedback.js is not created and the timeout happens when deployed. Running local seems to sidestep this problem... at least that's my theory.
  3. My plan to fix is make a feedback page instead.
  4. When I tried this, I first found that the sg mail package needed a polyfill for the fs package. So updated next.config.js to include this:

    webpack: (config) => {
    config.resolve.fallback = { fs: false };
    
    return config;
    },
  5. Next I discovered that env variables that worked with the api folder code, would not work with a page. Finally found that I needed to add something else to next.config.js to allow the app to see the HELP DESK vars. The in total the file is now:

    module.exports = {
    env: {
    NPM_PACKAGE_VERSION: process.env.npm_package_version,
    HELP_DESK_EMAIL: process.env.HELP_DESK_EMAIL,
    HELP_DESK_TOKEN: process.env.HELP_DESK_TOKEN,
    BUILD_NUMBER: require('child_process')
      .execSync('git rev-parse --short HEAD')
      .toString().trim(),
    },
    webpack: (config) => {
    config.resolve.fallback = { fs: false };
    
    return config;
    },
    }

@superdav42 FYI

superdav42 commented 1 year ago

The root cause of the problem is in v4 of @netlify/plugin-nextjs api function operate very differently from v3. I think all the other apps are using v3 of this plugin and v11 or v10 of nextjs. Since this is a newer repos we set it up with the latest. v4 of the plugin seems to create one function called ___netlify-handler which handles all api requests. V3 creates a function for each endpoint in our case it's called next_api_feedback. Because of this bug https://github.com/netlify/next-runtime/issues/1174 when using v4 the function timesout on AWS lambda after 10s while it is starting up before it can serve any requests. PR #122 Fixes the problem by downgrading @netlify/plugin-nextjs to v 3.9.2 and and next js to v11.1.4. The app seems to work fine on the older versions so I think we'll keep it this way for now.

To get the latest version working according to the issue we will probably need to update all the l rcl's to change the imports as described.

One can see the problem using the netlify-cli and running netlify serve. The file at `.netlify/functions/___netlify-handler.zip should be much smaller and not contain all the mui icons and mui code. As it is the file is 27MB but the next_api_feedback.zip with v3 is 600KB. Before the v4 code will work the generated zip will probably need to be less than 1MB.