S
S
s_katala2018-02-13 13:04:53
Node.js
s_katala, 2018-02-13 13:04:53

How to define base_url?

Can you tell me how to determine the base url?
so that for example in hbs specify {{baseUrl}}/images/icon.png
and at the output my url is http://domain.ru/images/icon.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eQ1, 2018-04-15
@s_katala

var url = require('url');
var adr = 'http://domain.ru/images/icon.png?test=132';
var parsedUrl = url.parse(adr, true);

console.log(parsedUrl.host); //returns 'domain.ru'
console.log(parsedUrl.pathname); //returns '/images/icon.png'
console.log(parsedUrl.search); //returns '?test=132'

var queryTest = parsedUrl.query; //returns an object: { test: '132' }
console.log(queryTest.test); //returns 132

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question