Я пытаюсь собрать сервер, который работает на localhost: 5001.Я пытаюсь получить доступ, скажем, к Angular-приложению, работающему на localhost: 5002.Поэтому я хотел отобразить все приложение в моем теге div, как показано ниже.,Когда я попытался получить запрос на localhost: 5002, я смог получить HTML-контент.Но у него есть тег.когда я проверил сетевой вызов, вызов идет на http://localhost:5001/bundle.js. Это возвращает 404 файл не найден.Поскольку этого файла нет в моем http://localhost:5001/. Пожалуйста, помогите мне решить эту проблему.
Ниже приведен мой HTML-контент в http://localhost:5001. Я хотел, чтобы приложение Angular работалона локальном хосте: 5002 внутри тега div
<html>
<body>
<div class = "app"></div>
</body>
</html>
server.js
const express = require('express');
const server = express();
const request = require('request');
const proxy = require('http-proxy-middleware');
server.set('view engine', 'ejs');
// const createProxy = (path, target) =>
// server.use(path, proxy({ target, changeOrigin: true, ignorePath: true }));
// createProxy('/header', 'http://localhost:5002');
var options = {
target: 'http://localhost:5002',
changeOrigin: false,
ignorePath: true,
router: {
'localhost:5001': 'http://localhost:5002'
}
};
const custProxy = proxy(options);
server.use('/header', custProxy);
server.get('/', (req, res) => res.render('index'));
const port = 5001;
server.listen(port, () => {
console.log(`Homepage listening on port ${port}`);
});
Ниже приводится мой HTML-контент в http://localhost:5002
<html>
<body>
<app-root></app-root>
</body>
<script src = "bundle.js"></script>
</html>
server.js
var express = require('express');
var rp = require('request-promise');
var path = require('path');
var app = express();
//setting middleware
console.log(__dirname);
app.use(express.static(__dirname + '/dist/basic-routing-app')); //Serves resources from dist folder
app.get('/', (req, res) => {
const htmlPath = path.resolve(__dirname, '/dist/basic-routing-app', 'index.html');
// console.log(htmlPath);
// fs.readFile(htmlPath, 'utf8', (err, html) => {
// // const rootElem = '<div id="root">';
// // const renderedApp = renderToString(React.createElement(App, null));
// console.log(html);
// res.send(html);
// });
res.sendFile('index.html', {root: path.join(__dirname, '/dist/basic-routing-app')})
});
console.log("App is starting in 5002");
var server = app.listen(5002);