Skip to content

Instantly share code, notes, and snippets.

@onxssis
Created May 15, 2018 11:21
Show Gist options
  • Save onxssis/59a071d4fd6cbf9b89d3a43ea0ce9611 to your computer and use it in GitHub Desktop.
Save onxssis/59a071d4fd6cbf9b89d3a43ea0ce9611 to your computer and use it in GitHub Desktop.

Revisions

  1. onxssis created this gist May 15, 2018.
    14 changes: 14 additions & 0 deletions absolute path helper for adonisjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // add this to hooks.js in hooks.after.providersBooted fn

    View.global('absoluteUrl', function (path) {
    const req = this.resolve('request')
    let baseUrl = req.secure() ? 'https://' : 'http://'
    baseUrl += req.headers().host + '/'
    if (typeof path !== 'undefined') {
    path = (path.substring(0, 1) === '/')
    ? path.substring(1)
    : path
    return baseUrl + path
    }
    return baseUrl
    })