Unable to get the Response from angular7 services in production environment - angular7

I am new to angular and developed an angular application using angular CLI 7.
When I am running the application from my local system, I am getting the response from the service and it is working fine.
But when I deployed the application in the production server, I am unable to get the response from the service. Service is taking too long to respond and getting the HTTPErrorResponse of status Unknown Error.
We are using the Spring microservices for api calls to get the response data.
I am using the proxy.conf.json for the services because the URL running angular app is different from the service.
proxy.conf.json:
{
"/api/*":{
"target":"http://wsd185erd986.test.com/api",
"secure":false,
"loglevel":debug,
"changeOrigin":true
}
}
Changed the package.json to include the proxy.conf.json in proxyConfig.
Include the response headers in the service.
Could any one know on how to configure these proxy settings in production build for angular. Do we need to include any headers in the service calls.

HTTPErrorResponse - A response that represents an error or failure,
either from a non-successful HTTP status, an error while executing the
request, or some other failure which occurred during the parsing of
the response.
So as per the docs this error is thrown in multiple cases either there is an error at server end and server send the error response or there was some issue in parsing.
Please check the Spring Boot API request logs to see what response code is sent back.
You can check the API by a standalone client too (like Postman) and see if there is some issue.
As an aside - you should not be using angular development server in production as it is meant for angular development. Typically you can use any web server ( like Apache, NGinx etc) to host your angular production files ( they are merely static resources) and then either use them as a proxy ( by having their proxy configuration) or have CORS enabled services.

Related

Umbraco headless Node.js client cannot authenticate headless client

I have been trying to implement the Node.js client for Umbraco headless. I have done the following:
Set up Umbraco headless via my Umbraco cloud subscription
Implemented a simple app in Vue.js
Copied the example code from https://our.umbraco.com/documentation/Umbraco-Cloud/Headless/Headless-Node-Client/
when I run this code (via my localhost:8000) I get an authentication error
https://{MyUmbracoCloudUrl}/umbraco/rest/oauth/token 400 (Bad Request).
My config has the correct domain name for the cloud instance and the correct user name an password.
I get a 400 response from https://{MyDOMAIN}/umbraco/rest/oauth/token.
Does anyone have any ideas? I am not sure if this is a cors issue becuase I am trying to run this from my local host?
Cheers
L

Rails app not responding to Postman requests

My locally running rails app (on localhost:3000) responds to requests in the browser or from curl, but is not responding to requests from the desktop postman client, which immediately gives the generic "Could not get any response". Any idea what could be causing this?
For this you can use NGROK. It provides you a tunnel which can easily be used with postman or anyother such service. Download the library from here and run the tunnel as
./ngrok http 3000
or you can use lvh.me:3000 if your request is from same machine.

How do I avoid "preflight requests"?

I am trying to get started with Ember Data and immediately ran into this problem were the browser sends a OPTIONS request before the actual request.
The development backend I am trying to communicate with is a rails 4.2 server running on my local machine (started with rails s -b 0.0.0.0 )
I currently use this api to communicate from both an android and an ios app. My end goal is to provide an Ember app in addition to the existing rails UI, but if I have to replace it and only have the Ember UI, that will be OK.
I did some reading on CORS and I think at at least understand what it is trying to do. If I understand correctly, the browser sees the Ember app as having been served by a server other than the one that requests are being made to and because of this asks the server if this is OK.
So my questions are:
Will I be able to deploy my ember app to the real server such that these CORS OPTIONS requests are not needed? (ie, I assume a rails app can deliver an Ember app to the browser and the browser will see the source of the script as being the same as the target of the request and not require the prefight requests)
How do I get this to work in development? I see there is a --proxy option on the ember s --proxy, which seemed like it was supposed to be the solution for this, but I have not been able to get it to work
When I navigate to the server url I am trying to access http://localhost:3000/api/v1/users rails logs the following response:
Started GET "/api/v1/users" for 127.0.0.1 at 2016-04-17 10:02:01 -0400
Based on this, I think I have my Ember adapter set up correctly:
import JSONAdapter from 'ember-data/adapters/json-api';
export default JSONAdapter.extend({
host: 'http://127.0.0.1:3000',
namespace: 'api/v1'
});
Then I start the Ember server with this command:
ember s --proxy http://127.0.0.1:3000
The rails server is receiving the following request:
Started OPTIONS "/api/v1/users" for 127.0.0.1 at 2016-04-17 09:36:51 -0400
Which fails because I don't have a route for that (and don't think I want to either).
If you use --proxy you should not override your host!
The ember app should make all request to the current endpoint (probably localhost:4200) and the development server will redirect the requests to the backend.
If you:
Want to serve your ember app from your backend server in production, and
want to use --proxy in your development enviroment
don't set host on your adapter and just have fun. If you set host, ember will sent the data directly to this host, and not to your development server, resulting in a CORS request.

oauth: Meteor authentication issue on own server

I'm working on an app the requires a log-in by using oauth mechanisms from LinkedIn, Twitter, Google.
On the common meteor server this authentication method works fine.
However, I recently deployed the meteor server on my own server, and I get an authentication error when I try to log in. I tried linkedin and twitter and receive the same error, so I guess something is wrong on my server.
The error is in a browser window:
The requested URL /_oauth/linkedin was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.22 (Ubuntu) Server at exomodal.com Port 80
The meteor server is at port 3000.
Any ideas how to resolve this issue?
Thanks in advance
As far as I know, in Google, it asks for a redirect url and an origin url. During development, you registered these as localhost:3000/. But when you deploy, you are not using localhost anymore. Update these URLs in your "API console" (That's what they call it in Google) if any exists. As far as I know, Google and Facebook requires some sort of url registered.
Also, API configurations (client/consumer id and secret) are usually stored in the DB. Upon deploy, you don't usually ship your development DB, leaving behind the configurations which were on your development machine. What we did was to hard-code these into the server code, so that every time the server is restarted or redeployed to a "clean server", it inserts those configs to the DB.

Deploy Grails app to AppFog using Eclipse CloudFoundry plugin

I'm trying to deploy my Grails application to AppFog using CloudFoundry plugin (ver. 1.1) in Spring Source Suites (STS 2.9.2).
I'm using https://api.appfog.com as server address and MYAPPNAME.aws.af.cm for application address when deploying app.
Application is pushed and started, services are bounded but, after that, I recive error saying that:
Communication with server failed: I/O error: Server returned HTTP response code: 405 for URL: https://api.appfog.com/apps/MYAPPNAME/application
Also, when I try to create Caldecott tunnel toward database I recive response "The URIs: caldecott-85393a.appfog.com have already been taken or reserved. (404 Not Found)" which I also saw when (by mistake) treid to deploy application to MYAPPNAME.api.appfog.com (default AF name instead of particular infrastructure adress).
I suppose that CloudFoundry plugin uses default server address to reach application and also trying to create Caldecott tunnel on default server address (caldecott-85393a.appfog.com instead of caldecott-85393a.aws.af.cm)
Does anybody have idea how to circumvent this situation?
BR
Zoran
this doesn't sound like an issue with the plugin itself but the response coming back from AppFog's cloud. I would take this up as an issue with them and clarify you can use that plugin with their cloud.
AppFog had issues recently with their Java deployments that was specifically affecting Grails apps. This has been resolved and should be working seamlessly as expected now. You can always reach out for more information in the active google group as well: https://groups.google.com/forum/#!forum/appfog-users

Resources