Running GraphQL server on Google Cloud App Engine - node.js

In node.js to run the endpoint locally, I use the following snippet in my app.js
app.use('/graphql', (0, _expressGraphql2.default)(function (req) {
return {
schema: _schema2.default,
pretty: true,
context: _extends({ db: _models2.default }, (0, _isUser2.default)(req.headers['authorization'].split(' ')[1]))
};
}));
app.listen(8080, function () {
However, my app isn't receiving any response from the endpoint on trying to reach hostname:8080/graphql. This works on my local machine.

The title of your post indicates that your node.js app is deployed in Google App Engine. There is no need to worry about assigning an IP address to your instance in that environment. Instances are managed by the App Engine, and so is the routing of requests to your application.
To access the app, once deployed to the App Engine, one only needs to address it following the pattern: app_name.appspot.com. Alternatively, for a custom domain, you can follow the “Using Custom Domains and SSL” guide [1]. Sub-chapter “Adding SSL to your custom domain” of this document may help you with the setting up of SSL, if needed.
The app listens on port 8080 by default in the app engine. This is of no concern to an outside caller, who can only use the following the pattern: app_name.appspot.com to call the app. This situation is valid for the app engine environment.
[1] https://cloud.google.com/appengine/docs/flexible/nodejs/using-custom-domains-and-ssl

Related

Is http/express required when deploying socket.io web app

I'm trying to create a real time chat web app using Socket.io.
I used this code for server running on port 3000.
const io = require("socket.io")(3000, {
cors: {
origin: "http://127.0.0.1:5500",
methods: ["GET", "POST"],
},
});
Now I'm thinking of deploying my web app to railway.
I tried deploying the app to railway, it build successfully. Then updated client side with new server link, but it's not working.
I wanted to ask, will I need a web server (http or express) to handle incomming connections.
If yes, then why was it running fine before on my local machine and now it requires a web server.

Application deployed in Azure VM

I have a react application deployed using an Azure virtual machine. To access the app I need to use configured DNS, for example, "http://XYZ.eastasia.cloudapp.azure.com:3000". However, I don't want to include the port num in the URL. How can I port forward in azure so that only by typing 'http://XYZ.eastasia.cloudapp.azure.com' should be enough to access the application?
If you want to users access your app by URL: http://XYZ.eastasia.cloudapp.azure.com, you should run your react app on 80 port. Refer to this post to specify a port to run react app.

Anyway to configure server URL while running a docker image? (instead of hard coding in app)

I have an web application that is build using Angular 7 and I need to make an API call to get some data that I display in the App.
The API end point is an express server in node.js and it has some configuration to enable CORS from the web app's URL
I have created separate docker images for the Web App and the Middleware service and I plan to deploy them in the same server (linux machine on a cloud VM with some IP - a.b.c.d)
Since I know the IP of this VM I can hard code the API URL as a.b.c.d/api/foo in the Web App (Angular service) and white list the web app's URL in the middleware as a.b.c.d:3000
But there are situations where the IP address of the VM might change in the future and we also are going to automate the VM creation in the cloud and deployment using ansible scripts. In this case is there any way I can have some kind of placeholder in the Web App and Middleware and configure the URLs while running the docker image on the server? Or for the fact any URL that I might use in the application (say - a DB URL etc)
We already use this method so it will work for sure.
you can save url in environment.ts and call it on the page required
export const environment = {
production: false,
apiUrl : 'http://a.b.c.d:3000'
};
Service page to include url to service
export class CServices {
private url = environment.apiUrl;
constructor(){}
checkfunction() {
return this.http.post(this.url + '/api/', JSON.stringify(payload));
}
}

Write an https app in Node and use it on an Azure App Service

I have written a node.js application which I have been hosting on standard Linux server. It works fine, but I want to move it to Azure. I am not sure how to change the following lines:
var options = {
key: fs.readFileSync(process.env.CERT_KEY_PATH),
cert: fs.readFileSync(process.env.CERT_PATH)
};
if (process.env.CERT_BUNDLE) {
options['ca'] = [
fs.readFileSync(process.env.CERT_BUNDLE_ONE),
fs.readFileSync(process.env.CERT_BUNDLE_TWO),
fs.readFileSync(process.env.CERT_BUNDLE_THREE)
]
}
var server = https.createServer(options, app);
I have read this guide which tells me that instead of my certificated being read from a file the file system that I upload them in the portal.
Then in my node app do I just write var server = http.createServer(...) ?
And have Azure take care of the https part?
I have read this guide which tells me that instead of my certificated
being read from a file the file system that I upload them in the
portal.
Then in my node app do I just write var server =
http.createServer(...) ? And have Azure take care of the https part?
This is all correct. SSL termination is a feature of App Service. Your code should only host on port 80.
When deploying your API services in a cloud environment, you generally should let the platform take care of the SSL decryption instead of your application and not use self-signed certificates.
You would need a load balancer (or Application Gateway) in front of your NodeJs application to offload the https request via SSL offloading.
Refer:
https://learn.microsoft.com/en-us/azure/application-gateway/create-ssl-portal
#Sean,
You can follow the belwo article to deploy a node.js application azure app service.
Deploy NodeJs application in azure app srevice
Please ensure to set the set the Node runtime as per your project .
P.S.- Link which is posted above , we are using Azure CLI to deploy application.
Hope it helps.

IBM API Connect apps published to Bluemix inaccessible

I followed API Connect getting started guide to create a local loopback API app and tested successfully. Then I am trying to follow Publish Your API to Bluemix. The publishing is successful. The app is running. But clicking the app yields Chrome error:
This site can’t provide a secure connection
ddd.abbr-dev2.apic.mybluemix.net sent an invalid response.
I suspect the problem is incorrect port. According to CloudFoundry Nodejs tips, the port should use process.env.PORT, but loopback defaults to 3000. Following this clue, I tried adding config.local.js:
module.exports = {
port: process.env.PORT
};
But the service end point is still inaccessible.
Please Help. Thanks
This is actually by design. Since your API's implementation is on the public internet, it is secured via Mutual TLS. The only way to access it is via the API Connect gateway, thus ensuring the API is managed.
If you want to make it accessible publicly, open the app in the Bluemix console and add an additional route to the app, using the mybluemix.net domain.

Resources