How to deploy your flex app to different servers without hardcoding the URL?


After thinking much about this, I have arrived at a way to do this.

The need/requirement is this – Since I work in a startup, we keep changing servers, and their IP addresses. And being a  service oriented application – I need to be able to edit the webservice endpoints in my Flex application in a easy manner every time this happens.

My Solution for this -

Assumption is that my webservice endpoint looks like this -

http://<some-ip-address>/<appName>/ListAllServices/

1) Create a file config.xml in a folder named “settings” that sits in the root folder of your Flex application – outside the “src” folder. And the config.xml will be a simple xml file of the following format -

<?xml version=”1.0″ encoding=”UTF-8″?>
<applicationsettings> <url>localhost</url><appName>TestFlexApp</appName></applicationsettings>

At the end of this exercise the directory structure of your flex source code will look like this -

flex_src(root of the source code)
-com(some source folder)
–testapp
—view

-images
-settings
–config.xml
-appName.mxml

2) Now in your application code, setup a HTTPService object either in mxml or action script. Set the url of that object to this value- “settings/config.xml” – And the above xml fiel containing the current settings will be loaded into memory .

Now you can store these values in a singleton object and construct your Webservice call at runtime.

And whenever you want to move this to a new server in production, edit the <url> tag of your config.xml and you should be good to go.

And this can be automated as well via the EnvGen ant task.

Is there a better way to do this? I would like to know. Do leave a comment if you’ve got ideas on how to handle this.

About these ads

About vatsalad

Hi, I'm Vatsala
This entry was posted in flex, Flex Deployment Problems. Bookmark the permalink.

One Response to How to deploy your flex app to different servers without hardcoding the URL?

  1. Richard says:

    thank you this was very helpful. read about my implementation of this here:

    http://forums.adobe.com/message/3321291#3321291

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s