How to connect to express api deployed on Google App Engine? - google-app-engine

I have two services deployed on a project
default
api
1. default - Service running the react app
2. api - Service running the express app
I have a dispatch yaml the routes request incoming to either of the two services
dispatch:
url: 'xx.com/*'
service: default
url: 'api.xx.com/*'
service: api
I cannot seem to make any requests to the api.
The error that I'm hitting constantly is
POST https://api.xx.com/register net::ERR_NAME_NOT_RESOLVED

Related

React do not hit Django API on kubernetes

I have a django drf API and a react APP in a cluster kubernetes.
My API is not exposed (i cannot expose it because of security conditions).
React APP is exposed with an ingress.
React need to consume Django API (via axios). But it seems that axios requests are made by browsers so api service is unreachable.
Need someone already faced this issue?
Thanks in advance!
Gauthier
Your Django API must be accessible from inside. Use some Load Balancer service like ELB in AWS or SLB in Aliyun to redirect your browser requests to your Django API service.
This way your Django API service could be exposed through Nodeport service or inner ingress.

AWS backend deployment

I deployed a React App on AWS with amplify. Now I developed an express backend which communicates with the React frontend.
Now I am wondering if there is a way to host the backend within the same project as the react app on AWS using amplify. So hosting the whole Fullstack App with amplify.
I have read a lot about hosting backend with amplify. But from the documentation it looks like that I can only use the backend-services provided by aws using Amplify CLI and not my own express backend.
Does anyone have experience with hosting their own express backend using Amplify?
As I do not have much experience with cloud-hosting at all, I would be very thankful for some help :)
Best regards from Germany
Jan
Usually, on Amplify you use AppSync for the backend.
This way you have your full-stack on Amplify
With the API you can easily add the basic operations of an API, and customize the more specific ones using lambdas.
But if you still need to host your own, you can add a lambda function for your backend, check this article about running ExpressJS on a lambda.
If you add it via Amplify-CLI (amplify function add) you can see it on the Amplify Console, including logs and other details about it.
I'll go through both scenarios in more detail below:
Custom operations with AppSync
In case you decide to use DynamoDB/AppSync with GraphQL interface you can define your custom operations on the GraphQL Schema.
i.e:
Create a lambda function MyCustomOperation
Define the operation, input and the return you want from your operation (you can use Javascript)
On your GraphQL schema use the #function directive to associate the function to the query desired
type Query {
myCustomQuery(input: String): String #function(name: "MyCustomOperation-${env}")
}
See more details here
Express Backend
In case you need your full backend
To add it to your Amplify project you can create a lambda function
amplify function add and select the template Serverless express function (Integration with Amazon API Gateway), the documentation has more details.
It will give your API endpoint, which you provide on the next step.
You can now manually set it on the configuration as informed here
Amplify.configure({
// OPTIONAL - if your API requires authentication
Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
},
API: {
endpoints: [
{
name: "MyAPIGatewayAPI",
endpoint: "https://1234567890-abcdefgh.amazonaws.com"
},
{
name: "MyCustomCloudFrontApi",
endpoint: "https://api.my-custom-cloudfront-domain.com",
}
]
}
});
Then you just need to adjust the lambda function with the code you already have for the backend.

Import Logics App HTTP request endpoint in API management service in Azure

I want to import/ associate my Logics App HTTP request trigger endpoint into API management service; I can't find the URL endpoint when I create an API in API management create form.
Please advise

How to use google authentication for an angular web app and a .net web api hosted on azure

I have an angular web app talking to a c# .net web api back end.
They are both hosted on azure app services.
Azure app services offers a suite of authentication services and I've chosen to use google auth.
I've got my google client id and secret setup in azure google auth and my web app correctly shows and prompts me for my google credentials.
My problem now, is that i need my web api back end to authenticate the web app google token. I couldn't find any articles or tutorials that demonstrates the following:
How to get and send the token to the web api? I've read that azure app service should automatically inject the necessary auth headers but any calls to my api do not include those headers. Should i manually call auth/me and add them to the request header?
How do i get my web api to authenticate the details from the request header with google auth? Do i need a separate client id for the web api or should i re-use the web app client id?
Cheers!
According to your description, I assumed that you are using the built-in Authentication / Authorization provided by Azure App Service.
AFAIK, App Service Authentication (Easy Auth) provides two flows: client-managed and server-managed flow. For the server-managed flow, the server code manages the sign-in process for you, and your backend would directly receive the token from the relevant identity provider (e.g. Google, AAD,etc.), then both generate a authenticationToken for browser-less apps and AppServiceAuthSession cookie for browser apps. Details you could follow Authentication flow.
For your angular web app, you could just use server-managed flow, after user successfully logged, you need to call https://<your-angular-app-name>.azurewebsites.net/.auth/me to retrieve the google access_token, then send the following request against your web api endpoint for retrieving the authenticationToken as follows:
POST https://<your-webapi-app-name>.azurewebsites.net/.auth/login/google
Body {"access_token":"<the-google-access-token>"}
After successfully retrieved the authenticationToken from your Web API endpoint, you could send the following subsequent requests for accessing your APIs:
GET https://<your-webapi-app-name>.azurewebsites.net/api/values
Header x-zumo-auth:"<authenticationToken-generated-by-your-webapi>"
Moreover, you could also use client-managed flow in your angular web app, you may need to directly contact with your identity provider (Google) to retrieve the access_token in your client via Auth0 or google-signin or other third-party libraries. Then you may need to both send request to your angular web app and Web API web app for retrieving the authenticationToken as the above request sample.
Do i need a separate client id for the web api or should i re-use the web app client id?
Per my understanding, you must use the same google application. For AAD authentication, you could configure a AAD app with the access permissions to another AAD app.

How to persist authenticated state in a sailsJS backend app when requests are from another domain?

I have an architecture where I'm using sailsJS (custom node.js implementation) as my api server and an angular front end server. Each app is being served from different domains.
How can I maintain an authenticated session in the sailsJS api app between requests?
Sails has an integrated req.session object for maintaining sessions but it doesn't seem to be working out of the box when the client is being served from another domain.
You need to check two things when doing cross-origin requests from your front-end app to your Sails app:
Make sure your Sails app has CORS enabled; this will ensure that the browser doesn't block the requests for security reasons
Make sure the withCredentials flag is set in your AJAX request; this will ensure that your cookie is sent to Sails and your session is maintained.
With Restangular, you can set withCredentials to be used on all requests by default using setDefaultHttpFields; see this answer for details.

Resources