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

filters not working in production #4983

Closed
3 tasks
cramervincent opened this issue May 24, 2024 · 3 comments
Closed
3 tasks

filters not working in production #4983

cramervincent opened this issue May 24, 2024 · 3 comments

Comments

@cramervincent
Copy link

Description

I have Pocketbase running on a VPS, and the URL is set by NGINX to https://api.vincent-dev.xyz/.

The issue I'm experiencing is that when using filters or pagination, I always get all the results without the filter being applied. For example:

https://api.vincent-dev.xyz/api/collections/products/records?filter=(price=62)

Expected Result:

Should return just 2 objects.

Actual Result:

Returns all objects.

However, when I run the following command locally:

curl "http://localhost:8090/api/collections/products/records?filter=(price=62)"
I get the correct result of just 2 objects.

Steps to Reproduce

  • Deploy Pocketbase on a VPS.
  • Set up NGINX to route the URL to https://api.yourdomain.com
  • Use a filter in the API request, e.g., ?filter=(price=62).

Expected Behavior

The API should return filtered results based on the specified filter criteria.

Actual Behavior

The API returns all the records, ignoring the filter criteria.

Further information

my NGINX config file

server {
    server_name api.vincent-dev.xyz;

    location / {
        proxy_pass http://localhost:8090;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        proxy_buffering off;
    }

    location ~* ^/api/(.*) {
        proxy_pass http://localhost:8090/api/$1;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        proxy_buffering off;
    }

    location ~* ^/pb/(.*) {
        proxy_pass http://localhost:8090/_/$1;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        proxy_buffering off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.vincent-dev.xyz/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api.vincent-dev.xyz/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = api.vincent-dev.xyz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name api.vincent-dev.xyz;
    return 404; # managed by Certbot
}

@ganigeorgiev
Copy link
Member

I don't understand your nginx config but I don't think this is a PocketBase issue.

The filter query parameter is working correctly. There are also integration tests that verify the correct behavior.

Make sure that the query parameter value is URL encoded (the SDKs do this automatically). In your case your url should be:

http://localhost:8090/api/collections/products/records?filter=price%3D62

If you still think that this is a PocketBase issue, please export your collections configuration as json (Admin UI > Settings > Export collections) and I'll try to have a more detailed look, but again it is most likely a client-side error.

@ganigeorgiev
Copy link
Member

Note that since you are using a variable ($1) in the proxy_pass directive you may have to forward manually the query parameters too, aka. try changing it to:

proxy_pass http://localhost:8090/api/$1$is_args$args

But as mentioned earlier I don't exactly understand your Nginx config and the need to be split in 3 components so it may not be what you are looking for.

@cramervincent
Copy link
Author

Thank you so much, your last comment did the trick!

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

2 participants