Hi!
I am new to render .com and I am currently hosting a Node js server on the WEB SERVICE function that uses code from my private GitHub repo. And I also have a private GitHub repo for my client-side website that is hosted on GitHub Pages. The question I have is how can I secure the data between the client and the server. I am using HTTPS when fetching data from the server to the client and I am wondering what I need to change in the server code to always / only support HTTPS and how the system works with SSL keys. The keys are supposed to be auto-generated on render .com but do I need to point to them in the server code or something?
How I fetch data from the server on the client website:
const fetchData = async () => {
try {
const response = await fetch(‘https:// your-server-api-url/getSomeData’);
const data = await response.json();
setData(data);
} catch (error) {
console.error(‘Error fetching data:’, error);
}
};
How my server node js code looks:
const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const app = express();
const cors = require(‘cors’);
const dotenv = require(‘dotenv’);
dotenv.config();
const dbService = require(‘./dbService’);
app.use(bodyParser.json({ limit: ‘100mb’ }));
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({extended : false}));
app.get(‘/getSomeData’, (request, response) => {
const db = dbService.getDbServiceInstance();
const result = db.getAllData();
result
.then(data => response.json({data: data}))
.catch(err => console.log(err));
response.json({success: true});
});
app.listen(process.env.PORT, () => console.log(‘app is running’));
Any help would be gladly appreciated😊