开发者

Javascript "development" and "production

开发者 https://www.devze.com 2023-03-09 00:48 出处:网络
I\'m developing a simple application in Sinatra that makes many asynchronous calls. In my javascript code I have a variable that stores my domain for all calls. My problem is how to alter the value of

I'm developing a simple application in Sinatra that makes many asynchronous calls. In my javascript code I have a variable that stores my domain for all calls. My problem is how to alter the value of the variable every time that I publish my application, for example:

var url = "http://localhost:9292"; //development

to

var url = "http://mysite.com" //production

I would like to automate this, to prevent errors in deployed application. Is it possible?

I thought about doing this in my "View" using ruby code, but do not know if it is cool.

S开发者_C百科orry my English.

Thanks.


Maybe you can use:

var url = 'http://' + document.domain;

document.domain get the name of the current domain.


Try with:

window.location.port

This get the domain port of the currernt website ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消