adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

How to use adminjs after nginx rewrite?

Open helsonxiao opened this issue 2 years ago • 0 comments

Describe the problem feature solves Our service is deloyed in a k8s pod and we want to keep it simple. So it has no built-in prefix like /api/v1, /api/v2. We found that adminjs is not accessible after k8s nginx ingress rewrite.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-dev
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/service-weight: ''
    nginx.ingress.kubernetes.io/force-ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - xxx.xxx.com
      secretName: xxx
  rules:
    - host: xxx.xxx.com
      http:
        paths:
          - path: /api/v2(/|$)(.*)
            backend:
              serviceName: xxx-dev
              servicePort: 3000

We've tried to rewrite path for assets /admin/frontend/xxx to make it accessible, but we still cannot change router action(It'll be broken after page refreshed and we can not even do a save action...).

metadata:
  name: xxx
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^/adminjs/(.*?)$ /api/v2/adminjs/$1 redirect; # add prefix for adminjs assets

Here's the dependency list:

  "dependencies": {
    "@adminjs/express": "^4.0.0",
    "@adminjs/nestjs": "^3.0.0",
    "@adminjs/typeorm": "^2.0.0",
    "@nestjs/common": "^8.0.10",
    "@nestjs/core": "^8.0.10",
    "@nestjs/platform-express": "^8.0.10",
    "@nestjs/swagger": "^5.1.0",
    "@nestjs/typeorm": "^8.0.2",
    "adminjs": "^5.2.1",
    "express": "^4.17.1",
    "express-formidable": "^1.2.0",
    "express-session": "^1.17.2",
    "swagger-ui-express": "^4.1.6",
  }

Describe the solution you'd like Swagger works just fine in our case. Maybe we don't need to change any APIs, but let adminjs solve it internally.

Describe alternatives you've considered None.

Acceptance criteria

  • [ ] a workaround?
  • [ ] a patch

helsonxiao avatar Nov 26 '21 10:11 helsonxiao

There was no discussion over this issue for past year. Closing due to lack of activity.

krzysztofstudniarek avatar Aug 16 '22 09:08 krzysztofstudniarek