0

I have an AngularJS webapp. I want to port it to Ionic to create hybrid app. I have figured out that I need to put all my code in www folder after creating an Ionic app and need to include cordova.js to my scripts along with meta Content-Security-Policy.

I am able to see my homepage when I start the server using "ionic serve" command but the problem is that it is trying to fire REST call on localhost:8100 but my server is running on localhost:8080.

How do I tell the app to fire call to localhost:8080? Also what about the CORS? Will it get resolved by meta Content-Security-Policy?

Any step by step tutorial will be of a great help.

Thanks

2 Answers 2

2

For CORS include this in your index.html

   <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

To Know more about whitelist plugin refer nicRobay blog and in your chrome add this extenstion.

Usually on give ionic serve command the terminal itself asks which port to use commonly you can use localhost:8080 if you get that an option.

To include the corodova refer `this' and add this line.

<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>

or you can use bower to install cordova.

Sign up to request clarification or add additional context in comments.

1 Comment

I have already added the same meta tag for CORS. Hope this should solve the problem. Now for the "ionic serve" command, it runs a server at some port(default is 8100). The problem here is that my backend server is running at port 8080 and I can not run one more server at the same port... All my rest calls are relative like $http.get("rest/users/1").success(successCallback).error(errorCallback) If I port the same code to ionic then it tries to fire a call to port 8100 but since the backend server is running on 8080 the call fails. how can i fix this?
0

I think I went in wrong direction and asked this question. In mobile app to make a rest call the host should be hardcoded or in someway hostname should be provided by the user.

The same webapp can't be ported to hybrid app as it is because relative urls need to be changed to absolute url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.