polymer 1.0 - how to configure server host ip address and port in cordova app for ajax calls -


i trying convert 1 of web app hybrid mobile app using cordova. using polymer , web components. able render ui in ios device also. want know how configure ip address , port of server (my laptop in case) dynamicallly when building or depolying app. may cordova setting (like env variable or build argument)

my html

<html lang="en">  <head> <meta charset="utf-8"> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script> <link rel="import" href="styles/app-theme.html"> <link rel="import" href="bower_components/paper-toolbar/paper-toolbar.html"> <link rel="import" href="bower_components/paper-drawer-panel/paper-drawer-panel.html"> 

some ajax call.

<iron-ajax id="resetvalidate" **url="/api/appusers/reset"** method="post" content-type="application/json" on-response="handleresponse" on-error="handleerror"></iron-ajax> .... 

so want call http::/192.168.1.39:3000//api/appusers/reset in case, changing code not solution, have more 100 places , more on ip different developers , change every time. when application ready need configure baseurl apis also, want know way in cordova this.

this works in web application / browser render html , js files api same express server. hostname , port same static , dynamic content , localhost during development.

just use javascript global variable. instead of hard-coding url, use global variable concatenated rest of path. way, need set url in 1 place each developer machine.

yourcustomconfig.js
var globalserverurl = "http://localhost:3000"; part changes per dev machine.

allotherfilesneedingtousetheurl.js
globalserverurl + "/the/rest/of/your/path" everywhere build path http request. none of these ever need updated again.

make sure value of global variable set production server location in source control, , you're go.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -