I could not find any solutions that worked for me.
I am trying to create a simple microservices architecture with Node.js instances. The gateway microservice does not load the html with CSS, JS like the homepage microservice does.
At the moment I have 2 microservices:
- Express server that sends index.html as file. It loads correctly the page with assets (css, images, javascript). I have used
app.use(express.static('public'))
.
homepage:
const express = require('express')
const app = express()
var path = require("path")
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname+'/public/index.html'));
})
app.listen(3001, () => console.log('Homepage listening on port 3001!'))
- Express server that receives requests and wants to deliver content to user. I am trying to create an API Gateway to filter traffic (on authentication for example) and write logs.
gateway:
const express = require('express')
const request = require('request-promise-native')
const app = express()
app.get('/', async (req, res) => {
// Write logs in database
const uri = "http://localhost:3001/"
const result = await request(uri)
res.send(result)
})
app.listen(3000, () => console.log('Public API Gateway listening on port 3000!'))
Any solution is really appreciated.
Thanks!