-2

I have put the nodejs on an azure dev ops virtual machine -- under the folder /api

I've ran pm2 but after 1-2 days it seems to fall down?

Can't add new command when connection is in closed state

"config add { "keepAliveInitialDelay": 10000, "enableKeepAlive": true, }"

  • where would you add this? In the package.json?

I am also struggling - because I need the node api server to run on HTTPS - the static webapps for react is built on https and its not wanting to talk to the http server. I need it fixed. I don't know where to begin - I've read tutorials on setting up a secure virtual machine and having to add certificates and pem keys? But I don't know how to ensure I don't break development/prod setup.

//start server
app.listen(process.env.PORT, () => {
  console.log(`Server running on port http://${process.env.BASE_URL}:${process.env.PORT}`);
});

env.prod -

PORT= 8080
BASE_URL = 51.132.222.164
FRONTEND_BASE_URL = 51.132.222.164
ENVIRONMENT=production

env.dev -

PORT= 5000
BASE_URL = localhost
FRONTEND_BASE_URL = localhost:3000
ENVIRONMENT=development

How to create an HTTPS server in Node.js?

const https = require(`https`);
const fs = require(`fs`);

const options = {
  key: fs.readFileSync(`test/fixtures/keys/agent2-key.pem`),
  cert: fs.readFileSync(`test/fixtures/keys/agent2-cert.pem`)
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end(`hello world\n`);
}).listen(8000);

http://expressjs.com/en/api.html#app.listen Would I have the https node listening to 443 or 8443? http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener

var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.cert')
};

// Create a service (the app object is just a callback).
var app = express();

// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
The Old County
  • 89
  • 13
  • 59
  • 129

0 Answers0