mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
simplify proxy
This commit is contained in:
parent
3d272ca297
commit
bbed5fca9a
2 changed files with 6 additions and 28 deletions
|
@ -18,26 +18,8 @@ module.exports =
|
|||
# - an Object with:
|
||||
# - a path attribute (String)
|
||||
# - a baseURL attribute (String)
|
||||
# - a baseURL attribute (Object) with:
|
||||
# - a setting attribute pointing to a value in the settings
|
||||
makeTargetUrl: (target) ->
|
||||
return target if typeof target is 'string'
|
||||
return target.path unless target.baseUrl?
|
||||
"#{target.baseUrl}#{target.path or ''}"
|
||||
|
||||
if typeof target.baseUrl is 'string'
|
||||
baseUrl = target.baseUrl
|
||||
else if target.baseUrl.setting?
|
||||
baseUrl = digSettingValue target.baseUrl.setting
|
||||
|
||||
return null unless baseUrl?
|
||||
"#{baseUrl}#{target.path}"
|
||||
|
||||
# given a setting path (e.g. 'apis.v1.url') recursively find the corresponding
|
||||
# settings value
|
||||
digSettingValue = (attributesPath, dig = null) ->
|
||||
dig ||= settings
|
||||
[nextAttribute, leftAttributes...] = attributesPath.split('.')
|
||||
dig = dig[nextAttribute]
|
||||
return null unless dig?
|
||||
return dig if leftAttributes.length == 0
|
||||
digSettingValue(leftAttributes.join('.'), dig)
|
||||
|
|
|
@ -47,18 +47,14 @@ describe "ProxyManager", ->
|
|||
target = 'http://whatever'
|
||||
@proxyManager.makeTargetUrl(target).should.equal target
|
||||
|
||||
it 'makes from object', ->
|
||||
it 'makes with path', ->
|
||||
target = path: 'baz'
|
||||
@proxyManager.makeTargetUrl(target).should.equal 'baz'
|
||||
|
||||
it 'makes with baseUrl', ->
|
||||
target = baseUrl: 'foo.bar'
|
||||
@proxyManager.makeTargetUrl(target).should.equal 'foo.bar'
|
||||
|
||||
it 'makes with baseUrl and path', ->
|
||||
target = path: 'baz', baseUrl: 'foo.bar/'
|
||||
@proxyManager.makeTargetUrl(target).should.equal 'foo.bar/baz'
|
||||
|
||||
it 'makes with settingsUrl', ->
|
||||
@settings.apis = v1: url: 'foo.bar/'
|
||||
target = path: 'baz', baseUrl: { setting: 'apis.v1.url' }
|
||||
@proxyManager.makeTargetUrl(target).should.equal 'foo.bar/baz'
|
||||
|
||||
target = path: 'baz', baseUrl: { setting: 'incorrect.setting' }
|
||||
expect(@proxyManager.makeTargetUrl(target)).to.equal null
|
||||
|
|
Loading…
Reference in a new issue