Skip to content

Commit

Permalink
Support verdaccio > 5.19
Browse files Browse the repository at this point in the history
  • Loading branch information
n4bb12 committed Mar 4, 2023
1 parent 3ece1e7 commit f4f5125
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

### Compatibility

- Verdaccio 5.0 - 5.19
- Verdaccio 5.0 - 5.21
- Node 16
- npm 7+
- Browsers: See [browserslist](../.browserslistrc)
Expand Down
13 changes: 10 additions & 3 deletions src/server/flows/WebFlow.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { IPluginMiddleware } from "@verdaccio/types"
import { Application, Handler, Request } from "express"
import { getPublicUrl } from "verdaccio/build/lib/utils"
import { getPublicUrl } from "@verdaccio/url"

import { logger } from "../../logger"
import { getAuthorizePath, getCallbackPath } from "../../redirect"
import { buildErrorPage } from "../../statusPage"
import { AuthCore } from "../plugin/AuthCore"
import { AuthProvider } from "../plugin/AuthProvider"
import { ParsedPluginConfig } from "../plugin/Config"
import { mapValues } from "lodash"

export class WebFlow implements IPluginMiddleware<any> {
constructor(
Expand Down Expand Up @@ -74,9 +75,15 @@ export class WebFlow implements IPluginMiddleware<any> {
}

private getRedirectUrl(req: Request): string {
const baseUrl = getPublicUrl(this.config.url_prefix, req).replace(/\/$/, "")
const urlPrefix = this.config.url_prefix
// Stringify headers — Verdaccio requires `string`, we have `string |
// string[] | undefined`.
const headers = mapValues(req.headers, String)
const verdaccioReq = { ...req, headers }
const baseUrl = getPublicUrl(urlPrefix, verdaccioReq)
const baseUrlWithoutTrailingSlash = baseUrl.replace(/\/$/, "")
const path = getCallbackPath(req.params.id)
const redirectUrl = baseUrl + path
const redirectUrl = baseUrlWithoutTrailingSlash + path

return redirectUrl
}
Expand Down

0 comments on commit f4f5125

Please sign in to comment.