Ionic app REST calls to webapi hosted on localhost works using ionic serve, but not when I use "ionic run" - ionic-framework

Using Ionic serve -- My Ionic app returns data from my REST call to my webapi running on localhost.
But when I issue Ionic run , my REST API call fails. The error.data is blank, so I can't tell what the error is.
I am also able to hit the api of the rest call directly in my browser and see that it returns the data.
Would anybody please give me some pointers as to how to debug this, or why my http calls are failing in run mode?

ionic serve run on browser and ionic run with devices[ios or android]
change localhost to ip address(in your system)
ex- 198.1.1.0:4000(eg.4000 is port number of local server)
and type(CLI)
ionic serve --address 198.1.1.0
check on Mobile browser type 198.1.1.0:4000
Note

If you are using a live server for your REST application,you will run into CORS issues.
I would suggest, you use Ionic's proxy server to do all your request. You will not run in any OPTION request or null request response etc etc.
Check This Official Blog and,
This will also be very helpful Ionic Proxy Example

localhost server is only accessible from your local environment (laptop). Assuming you are running on an actual device, it cannot access that web api in a normal way.
You can use following steps:
Open hotspot from your device
Connect your laptop to the network
Open terminal and type in ipconfig
Call your REST with the specified IP address.
You can find detailed reference here.
How can I access my localhost from my Android device?

I found the solution to my problem in this blogpost. It explained the network host configuration used by GenyMotion emulator : http://bbowden.tumblr.com/post/58650831283/accessing-a-localhost-server-from-the-genymotion
Using this I was able to get the ip address that I should use when invoking my service, that was hosted on my local IIS server.

Related

Circumventing web security limitations between two sites on the same server

I'm using Eclipse to develop an app that consists of an Angular 2 front end and a Java REST back end.
For the front end, I'm using the Angular CLI plugin, which starts the app by issuing an ng serve command to the CLI. This command sets up an http server on port 4200.
For the back end, I'm using an in-company framework that launches in Jetty within Eclipse in port 8088.
While both these ports are configurable, by nature of the frameworks and plugins in use, they'll always be distinct.
Authentication works via an OAuth2 service that is also deployed to port 8088, as part of the framework. This service sets a cookie which certifies the browser session as authenticated. I have verified that this service works correctly by testing it against a Swagger instance of the REST API (also running in 8088 as part of the same framework).
The problem is that when the browser is aimed at the Angular 2 app on :4200, its internal REST API requests to :8088 aren't carrying the authentication cookie. Presumably, this is because of cross-site protection.
Is there any way for the app or the framework to tell the browser that these two "sites" are actually part of the same system?
Alternatively, if I have to configure the dev browser (Chrome) to work, I can live with that too. However, I've tried the --disable-web-security --user-data-dir recommendation, but the cookie still doesn't show up on the requests.
Lastly, I have Apache installed on the dev machine. If I can set up appropriate vhosts and use it as a proxy so that the browser thinks it's all the same, that would probably work too. It would just be a matter of intercepting all /swagger and /api requests and sending them to :8088, and all forwarding all other requests to :4200. However, I've been banging my head against mod_rewrite and mod_proxy and haven't been able to come up with anything that works.
I think what you're looking for is
withCredentials = true
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

How to test Messenger Bots offline? Local webhooks

I'm starting with Messenger Platform API. I want to make simple Messenger Chatbot. Here is tutorial I follow.
As you see, to start I need to set up webhook (step 2). So basically: web server that provides some REST API and posts some data back. The problem is: facebook requires me to provide some real, existing app URL that works currently in internet. So, do I need to upload my code to server each time I change something? Can I somehow test it locally (on my localhost)? How can I test behavior of my bot?
There's a few services you can use to expose your webserver running on localhost to the public. Two options are localtunnel and ngrok.
An example (from localtunnel's quickstart) of how you might do this, given that your webserver is running at http://localhost:8000/ would look like this:
Install localtunnel from npm:
npm install -g localtunnel
Request a tunnel to your local server:
lt --port 8000
This will generate a link, of the form https://foo.localtunnel.me you can use to access your localhost from the web. One nice feature is that you automatically get https so Facebook won't give you a 'SSL certificate problem' error. Localtunnel or ngrok are also nice for sharing work running locally with others.
Note that the localtunnel url is only valid as long as the connection lives, so you will have to update the url Facebook has if the connection ends.
I created a library that tries to solve this exact problem! With fb-local-chat-bot you can easily test your bot offline. The library also makes testing much more simple. If you're interested, definitely check it out
https://github.com/spchuang/fb-local-chat-bot
Demo:
you may use ngrok to test the messenger bot in localhost. You may download it at:
https://ngrok.com/download
on executing ngrok, it will generate secure link that can be used as a end point in webhook.
You can also check the detailed status of each request and response of ngrok through
http://localhost:4040/inspect/http
Later, once you are done, you may deploy your code to secure server.
You can find more info as to how to build a basic chat bot on the link below:
How to build a basic chat bot on facebook messenger
You can deploy your backend services on heroku free of cost. It provide public DNS with RSA.
If you can't use ngrok for some reason (like routing webhook to multiples dev machines). please try this emulator i have created for developing / debugging webhooks locally. this provides emulation of send api and a messenger ui
I have created an emulator for send api and messenger which i use for debugging web hooks locally
https://github.com/SonOfSardaar/facebook-send-api-emulator
I also came across this (i have not tried this one yet but looks good)
https://learn.microsoft.com/en-us/bot-framework/debug-bots-emulator

Viewing MEAN app in Google cloud

I am trying to access a barebone MEAN stack application with Google's glcloud one click deployments. I have successfully been able to add the code for the MEAN app and can access (via ssh) and run/start app using grunt. Neither of the external links provided by gcloud is working: http://:3000 or http://
Any idea on how to access app for viewing/testing?
I figured it out by allowing the default MEAN JS port 3000 on the firewall rules in the Google Developer Console. Networking > Firewall rules. You must also allow http port for incoming traffic.

IIS Arr not passing windows credentials on the same server

I have a self-hosted owin web api service on a test environment, and to give it a better name I use a domain alias, and ARR.
My web api runs on port 8888, and uses Windows Authentication. I have configured my arr to run under testserver:80 with anonymous authentication. I want to deploy a service on the box that will pool the webapi for data. When I try to visit testserver from my web browser on my desktop it works fine. However, when I remote into that box and try to hit testserver it prompts me for credentials. Even if I type them correctly it still will issue me a 401. If I go to localhost:8888 the site will work.
Since, I'd prefer to use the pretty name for the server in my service how do I correct this issue. How do I get it to pass credentials on the same box through ARR?
You might have have an issue with LSA loopback checking.
You get the 401 because ARR forwards your Windows Authentication to localhost, which is not allowed (default setting).
Try to disable LSA loopback checking (restart most probably required). If that works you can limit the disabling of loopback checking to specific websites (to prevent security holes).
See You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version for more information on the LSA loopback check and how to disable it completely or only for specific hostnames.

Can't Authenticate with Local .NET back-end

I've followed the guide:
Getting Started with Authentication with Mobile Services .NET for Windows Store
I'm able to run the service locally as long as I don't need to authenticate the user. I can also authenticate the user if I publish the service to Azure. But I want to be able to test and authenticate the user locally. How can this be done?
I'm using Live ID and I have the correct ClientID and ClientSecret set in the Web.config. When I attempt to call LoginAsync from the client the call fails with The request could not be completed. (Method Not Allowed)
** Update 2014-03-20 **
Based on the comments of Carlos and Henrik, I've updated my local service to look exactly like my server instance. I followed Scot Hanselmans excellent guide and now I have my service running locally on port 80 and port 443 with a completely valid SSL certificate. It's even running on the exact same https://xxxx.azure-mabile.net hostname.
With these changes, there is now no configuration difference whatsoever between running the app against my local machine or running it against Azure. I can go to https://xxxx.azure-mabile.net in the browser, get redirected to Live login, sign in, and get redirected back to the service successfully. In the browser it all works. However it still doesn't work in the app.
I attached the debugger, set CLR errors to "break when thrown" and I managed to trap the exception in the service. Here's what I see in the immediate window:
The Response property is not helpful. It does not provide any additional information about the problem.
The only thing that stands out to me is that the app is trying to do a POST to /login/microsoftaccount while the browser would normally be doing a GET at this address (then getting redirected).
** Update #2 2014-03-20 **
After following Henriks guide for remote debugging I was able to load symbols and get a tiny bit more information:
"An existing connection was forcibly closed by the remote host"
The error code is 10054 (WSAECONNRESET) Connection reset by peer.
It appears the Live Authentication server may be forcibly terminating the connection, but only when I'm authenticating with the app. Again, authentication within the browser is fine. This, combined with the fact that /login/microsoftaccount is a POST from the app seems to suggest there is a problem with the authentication token I'm getting back from LiveClient.LoginAsync. I'll do some more digging...
At the moment, it is set up so that you don't need authentication when running locally and access the service from localhost. In this case, anonymous access is let through (this is of course disabled while running in the cloud).
We don't really have a way for your to authenticate locally as redirect URIs won't work (they can't point to localhost as there is not way that Facebook, say, can resolve "localhost").
One option is that we somehow can mock the authentication locally and give you a token without connecting with the various identity providers. I am not sure exactly what that would look like but it is something we can consider.
Henrik
Did you perhaps set Mobile client app: Yes in your Live Connect project? I think that setting is meant to be used with the Live Connect SDK (client) flow, not the browser-based (server) flow. The client flow isn't supported yet with a .NET backend.
You also want to make sure you are using LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount) on the client to trigger the server flow.