mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: custom protocol header (#2156)
This commit is contained in:
parent
5b1aa87b76
commit
9c803993d0
3 changed files with 27 additions and 2 deletions
|
@ -33,3 +33,11 @@ url_prefix: '/second_prefix'
|
|||
|
||||
// url -> https://somedomain.org/second_prefix/'
|
||||
```
|
||||
|
||||
#### VERDACCIO_FORWARDED_PROTO
|
||||
|
||||
The default header to identify the protocol is `X-Forwarded-Proto`, but there are some environments which [uses something different](https://github.com/verdaccio/verdaccio/issues/990), to change it use the variable `VERDACCIO_FORWARDED_PROTO`
|
||||
|
||||
```
|
||||
$ VERDACCIO_FORWARDED_PROTO=CloudFront-Forwarded-Proto verdaccio --listen 5000
|
||||
```
|
||||
|
|
|
@ -641,7 +641,8 @@ export function getPublicUrl(url_prefix: string = '', req): string {
|
|||
if (!isHost(host)) {
|
||||
throw new Error('invalid host');
|
||||
}
|
||||
const protocol = getWebProtocol(req.get(HEADERS.FORWARDED_PROTO), req.protocol);
|
||||
const protoHeader = process.env.VERDACCIO_FORWARDED_PROTO ?? HEADERS.FORWARDED_PROTO;
|
||||
const protocol = getWebProtocol(req.get(protoHeader), req.protocol);
|
||||
const combinedUrl = combineBaseUrl(protocol, host, url_prefix);
|
||||
debug('public url by request %o', combinedUrl);
|
||||
return combinedUrl;
|
||||
|
|
|
@ -871,5 +871,21 @@ describe('Utilities', () => {
|
|||
expect(getPublicUrl(undefined, req)).toEqual('http://some/');
|
||||
delete process.env.VERDACCIO_PUBLIC_URL;
|
||||
});
|
||||
|
||||
test('with the VERDACCIO_FORWARDED_PROTO to override valid X-Forwarded-Proto https', () => {
|
||||
process.env.VERDACCIO_FORWARDED_PROTO = 'http';
|
||||
const req = httpMocks.createRequest({
|
||||
method: 'GET',
|
||||
headers: {
|
||||
host: 'some.com',
|
||||
'CloudFront-Forwarded-Proto': 'http',
|
||||
[HEADERS.FORWARDED_PROTO]: 'https',
|
||||
},
|
||||
url: '/',
|
||||
});
|
||||
|
||||
expect(getPublicUrl(undefined, req)).toEqual('http://some.com/');
|
||||
delete process.env.VERDACCIO_FORWARDED_PROTO;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue