@ninetailed/client-sdk-nextjs
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -89,4 +89,24 @@ import { v4 } from 'uuid'; | ||
function absoluteUrl(req) { | ||
var localhostAddress = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'localhost:3000'; | ||
var host = (req !== null && req !== void 0 && req.headers ? req.headers.host : window.location.host) || localhostAddress; | ||
var protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:'; | ||
if (req && req.headers['x-forwarded-host'] && typeof req.headers['x-forwarded-host'] === 'string') { | ||
host = req.headers['x-forwarded-host']; | ||
} | ||
if (req && req.headers['x-forwarded-proto'] && typeof req.headers['x-forwarded-proto'] === 'string') { | ||
protocol = "".concat(req.headers['x-forwarded-proto'], ":"); | ||
} | ||
return { | ||
protocol: protocol, | ||
host: host, | ||
origin: protocol + '//' + host | ||
}; | ||
} | ||
var buildSSRCampaign = function buildSSRCampaign(ctx) { | ||
var query = buildQuery(new URL(ctx.req.url, ctx.req.headers.host).toString()); | ||
var query = buildQuery(new URL(ctx.req.url, absoluteUrl(ctx.req).origin).toString()); | ||
return buildCampaign(query); | ||
@@ -96,3 +116,3 @@ }; | ||
var buildSSRPage = function buildSSRPage(ctx) { | ||
var url = new URL(ctx.req.url, ctx.req.headers.host); | ||
var url = new URL(ctx.req.url, absoluteUrl(ctx.req).origin); | ||
return { | ||
@@ -99,0 +119,0 @@ path: url.pathname, |
@@ -56,4 +56,24 @@ (function (global, factory) { | ||
function absoluteUrl(req) { | ||
var localhostAddress = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'localhost:3000'; | ||
var host = (req !== null && req !== void 0 && req.headers ? req.headers.host : window.location.host) || localhostAddress; | ||
var protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:'; | ||
if (req && req.headers['x-forwarded-host'] && typeof req.headers['x-forwarded-host'] === 'string') { | ||
host = req.headers['x-forwarded-host']; | ||
} | ||
if (req && req.headers['x-forwarded-proto'] && typeof req.headers['x-forwarded-proto'] === 'string') { | ||
protocol = "".concat(req.headers['x-forwarded-proto'], ":"); | ||
} | ||
return { | ||
protocol: protocol, | ||
host: host, | ||
origin: protocol + '//' + host | ||
}; | ||
} | ||
var buildSSRCampaign = function buildSSRCampaign(ctx) { | ||
var query = clientSdkCore.buildQuery(new URL(ctx.req.url, ctx.req.headers.host).toString()); | ||
var query = clientSdkCore.buildQuery(new URL(ctx.req.url, absoluteUrl(ctx.req).origin).toString()); | ||
return clientSdkCore.buildCampaign(query); | ||
@@ -63,3 +83,3 @@ }; | ||
var buildSSRPage = function buildSSRPage(ctx) { | ||
var url = new URL(ctx.req.url, ctx.req.headers.host); | ||
var url = new URL(ctx.req.url, absoluteUrl(ctx.req).origin); | ||
return { | ||
@@ -66,0 +86,0 @@ path: url.pathname, |
{ | ||
"name": "@ninetailed/client-sdk-nextjs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "./client-sdk-nextjs.umd.js", | ||
@@ -5,0 +5,0 @@ "module": "./client-sdk-nextjs.esm.js", |
14758
12
419