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

How to serve static file without passing from auth #4326

Closed
ShubhamRK96 opened this issue May 11, 2020 · 1 comment
Closed

How to serve static file without passing from auth #4326

ShubhamRK96 opened this issue May 11, 2020 · 1 comment
Labels

Comments

@ShubhamRK96
Copy link

I want to serve static files without passing the request from the auth in middleware.

In middleware.json

{
  "session": {},
  "auth": {
    "./middleware/checkAuth": {}
  },
  "parse": {},
"files": {
    "loopback#static": 
      {
        "name": "images",
        "paths": [
          "/assets/images"
        ],
        "params": "$!../assets/images"
      }
}

I want to bypass auth for serving static files.

@bajtos bajtos transferred this issue from loopbackio/strong-error-handler May 18, 2020
@bajtos
Copy link
Member

bajtos commented May 18, 2020

We are recommending users to configure static assets middleware in the files phase to avoid performance penalty paid when a request is first passed to the static middleware and then actually handled by the REST API layer. In such case, REST API requests are slowed down by filesystem checks performed by the static middleware.

In your case, the static assets are mounted on a subpath (presumably different from your REST API endpoints). In that case it should be fine to move the static middleware to an earlier phase, e.g. initial.

{
  "initial": {
    "loopback#static": {
      "name": "images",
      "paths": [
        "/assets/images"
      ],
      "params": "$!../assets/images"
    }
  },
  "session": {},
  "auth": {
    "./middleware/checkAuth": {}
  },
  "parse": {},
  "files": {}
}

@bajtos bajtos closed this as completed May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants