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:

  1. 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!'))
  1. 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!

New contributor
Cristian Ghinea is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Cristian Ghinea is a new contributor. Be nice, and check out our Code of Conduct.
 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.