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


#1

as per title, i need to get current user domain (req.headers.host) 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 && !!req.headers.host) {
        let parsedURL = url.parse(req.headers.host);
        Meteor.settings.public.domain = parsedURL.hostname || parsedURL.pathname;
    }
    return next();
})

client/view/layout.js

Template.layout.onCreated(function(){
    console.log(Meteor.settings.public.domain)
})

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_=