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

[Bug]: Default Invalidation Handler does not work correctly #6884

Open
1 of 3 tasks
samberrry opened this issue Jan 27, 2023 · 13 comments
Open
1 of 3 tasks

[Bug]: Default Invalidation Handler does not work correctly #6884

samberrry opened this issue Jan 27, 2023 · 13 comments
Labels
bug Bug reports

Comments

@samberrry
Copy link

samberrry commented Jan 27, 2023

Describe the Bug

We used redis cache driver, and caching is working very well.

When I call the invalidation URL I get error (default invalidation handler):

[dev:theme]  ERROR  [VSF][error]:  Cache driver thrown an error when invalidating cache! Operation skipped.

[dev:theme]  ERROR  [VSF][error]:  response.status is not a function

[dev:theme]   at handler (/Users/Documents/projects/binshops/vuestorefront/prestashop/node_modules/@vue-storefront/cache/nuxt/index.js:32:7)

[dev:theme]  ERROR  response.status is not a function

[dev:theme]   at handler (/Users/Documents/projects/binshops/vuestorefront/prestashop/node_modules/@vue-storefront/cache/nuxt/index.js:39:7)

My cache config:

    ['@vue-storefront/cache/nuxt', {
      enabled: true,
      invalidation: {
        endpoint: '/cache-invalidate',
        key: 'uniqueKey',
        handlers: [
          '@vue-storefront/cache/defaultHandler'
        ]
      },
      driver: [
        '@vue-storefront/redis-cache',
        {
          defaultTimeout: 86400,
          redis: {
            host: 'localhost',
            port: 6379
          }
        }
      ]
    }]

I use this url to clear redis:
http://localhost:3000/cache-invalidate?key=uniqueKey&tags=*

Current behavior

No response

Expected behavior

cache should be cleared after calling this url.

Steps to reproduce

No response

What version of Vue Storefront are you using?

any

What version of Node.js are you using?

any

What browser (and version) are you using?

any

What operating system (and version) are you using?

any

Relevant log output

No response

Able to fix / change the documentation?

  • Yes
  • No

Code of Conduct

  • I agree to follow this project's Code of Conduct
@samberrry samberrry added the bug Bug reports label Jan 27, 2023
@samberrry
Copy link
Author

@jeffpdotone
Copy link
Contributor

jeffpdotone commented Jan 31, 2023

Our team suggests doing the following.

Add the file below with the content.

plugins/body-parser.js

const bodyParser = require('body-parser')
const app = require('express')()

app.use(bodyParser.json())
module. Exports = app

Remember to add them in your nuxt.config.js

@samberrry
Copy link
Author

samberrry commented Feb 1, 2023

Hey @jeffpdotone ,
first I tried it with body-parser.js and yarn build ran with error: many Module not found: Error: Can't resolve fs. I thought the problem is that it should be bound to server-side only, so I changed it to body-parser.server.js. Code built and ran successfully, however still same error.

[dev:theme]  ERROR  [VSF][error]:  Cache driver thrown an error when invalidating cache! Operation skipped.
[dev:theme] 
[dev:theme] 
[dev:theme]  ERROR  [VSF][error]:  response.status is not a function
[dev:theme] 
[dev:theme]   at handler (/Users/Documents/projects/binshops/vuestorefront/prestashop/node_modules/@vue-storefront/cache/nuxt/index.js:32:7)
[dev:theme] 
[dev:theme] 
[dev:theme]  ERROR  response.status is not a function
[dev:theme] 
[dev:theme]   at handler (/Users/Documents/projects/binshops/vuestorefront/prestashop/node_modules/@vue-storefront/cache/nuxt/index.js:39:7)
[dev:theme] 

thanks

@samberrry
Copy link
Author

  plugins: [
    '~/plugins/body-parser.server.js'
  ],

@samberrry
Copy link
Author

content:

const bodyParserServer = require('body-parser');
const app = require('express')();

app.use(bodyParserServer.json());
module.exports = app;

@odranoelBR
Copy link

odranoelBR commented Feb 28, 2023

Same problem here using node v14 LTS.
We used the library whitout this problem for a long time and didn't have the problem.

Checking node HTTP Response object, the versions 12 14 16 don't have the method .status
https://nodejs.org/docs/latest-v14.x/api/http.html

Very strange, probably have plugins or something wrapping the object.

@odranoelBR
Copy link

odranoelBR commented Feb 28, 2023

I added the bodyparse on the middleware without errors, but still not solve the .status problem.
Screenshot from 2023-02-28 18-37-02

Info: The .status come from express https://expressjs.com/pt-br/4x/api.html#res.status
.status is a wrapper of .statusCode from HTTP Node response

@odranoelBR
Copy link

@samberrry Solved addyng the body parser to server middleware.
Screenshot from 2023-02-28 18-53-45

The invalidation cache endpoint works!

@samberrry
Copy link
Author

many thanks @odranoelBR , I will try it and I will update here, hope it solves the issue.

@tbanys
Copy link

tbanys commented Mar 6, 2023

works for me to. Thanks @odranoelBR

@skirianov
Copy link
Contributor

@samberrry if you're fine I will close this issue.

Do you think this could be useful to add to docs?

@samberrry
Copy link
Author

@skirianov
I guess a fix in validation handler is necessary,

I do not know how it should be handled, adding the fix snippet in docs or in package.

@skirianov
Copy link
Contributor

@samberrry let me add our TL, let's see what they think. @WojtekTheWebDev any ideas what would be the best solution here?

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

No branches or pull requests

5 participants