Get ASAP and define it to Meteor.setting.public while Template.onCreated

as per title, i need to get current user domain ( and define it to Meteor.setting.public.domain while inside Template.main.onCreated.

i cant use Meteor.absoluteUrl() because it’s for 1 domain 1 app concept. My use case was multiple domain for 1 app. The reason why i need the domain to be available in onCreated because i need to subscribe to database ASAP and get it ready for ?_escaped_fragment_=.

so any idea how this can work out?

so far what i can achieved is i have startup.js in server folder, here are the code

WebApp.connectHandlers.use((req, res, next) => {
    if (!!req.headers && !! {
        let parsedURL = url.parse(;
        Meteor.settings.public.domain = parsedURL.hostname || parsedURL.pathname;
    return next();



sometime it worked & output localhost (local development),
sometime doesn’t work & show 'undefined', i don’t know why

i tried using gadicohen:headers on client & server side, but this doesn’t work for ?_escaped_fragment_=