function detectServerBaseUrl(req) { if (req.headers.referer) { const url = new URL(req.headers.referer) return `${url.protocol}//${url.host}` } else if (req.headers.host) { const protocol = req.connection.encrypted ? 'https' : 'http:' return `${protocol}//${req.headers.host}` } else if (req.connection.remoteAddress) { const protocol = req.connection.encrypted ? 'https' : 'http:' return `${protocol}//${req.connection.localAddress}:${req.connection.localPort}` } return undefined}
NOTE: Refer https://nuxtjs.org/docs/2.x/internals-glossary/context#req