Javascript 未使用NGNIX、节点8.11和节点6正确路由的资源

Javascript 未使用NGNIX、节点8.11和节点6正确路由的资源,javascript,node.js,angular,express,nginx,Javascript,Node.js,Angular,Express,Nginx,我在当前设置中无法正确加载资产。我们使用NGINX,节点8.11,角度6 简而言之,我必须对进入node server.js的请求进行一些解析,以便为angular正确加载文件 以下是一个名为heroes的典型应用程序的设置: Nginx location /heroes/ { proxy_pass http://unix:///myapps/tmp/node.sock; proxy_set_header Host $host; proxy_set_header

我在当前设置中无法正确加载资产。我们使用NGINX,节点8.11,角度6

简而言之,我必须对进入node server.js的请求进行一些解析,以便为angular正确加载文件

以下是一个名为heroes的典型应用程序的设置:

Nginx

location /heroes/ {
    proxy_pass 
    http://unix:///myapps/tmp/node.sock;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header X-UA-Compatible "IE=edge";
}
节点服务器.js

...

//==============================================================
// Point static path to dist
//=================================================================
app.use(express.static(__dirname + '/dist/')); 
// set the static files location for the angular build
...
Node Server.js-创建允许的扩展列表

...

// Allowed extensions list can be extended depending on your own needs
const allowedExt = [
    '.js',
    '.ico',
    '.css',
    '.png',
    '.jpg',
    '.woff2',
    '.woff',
    '.ttf',
    '.svg',
    '.map',
    '.otf',
    '.eot',
    '.gif'
];
...
...    
// Redirect all the other requests
// TODO: This part is a hack. 
//The main issue is express not serving up the static assets
app.get('*', (req, res) => {
  if (allowedExt.filter(ext => req.url.indexOf(ext) > 0).length > 0) {
       var iFileStart=req.url.lastIndexOf("/");
       var sFile=req.url.substring(iFileStart+1);
       res.sendFile(path.resolve('dist/'+sFile));
    } else {
      res.sendFile(path.resolve('dist/index.html'));
    }
  });
Node Server.js-将文件路由到角度距离

...

// Allowed extensions list can be extended depending on your own needs
const allowedExt = [
    '.js',
    '.ico',
    '.css',
    '.png',
    '.jpg',
    '.woff2',
    '.woff',
    '.ttf',
    '.svg',
    '.map',
    '.otf',
    '.eot',
    '.gif'
];
...
...    
// Redirect all the other requests
// TODO: This part is a hack. 
//The main issue is express not serving up the static assets
app.get('*', (req, res) => {
  if (allowedExt.filter(ext => req.url.indexOf(ext) > 0).length > 0) {
       var iFileStart=req.url.lastIndexOf("/");
       var sFile=req.url.substring(iFileStart+1);
       res.sendFile(path.resolve('dist/'+sFile));
    } else {
      res.sendFile(path.resolve('dist/index.html'));
    }
  });

角度索引.html

...    
<base href="/heroes/">
...
然后我在浏览器中得到这个错误:

似乎可以找到这些文件,但没有作为JS文件进行处理


有什么建议吗?

好的,我自己想办法

必须编辑以下内容:

NGINX:

location /heroes/ {
    root /app/mydir/heroes/dist <--- added this
    proxy_pass http://unix:///myapps/tmp/node.sock;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header X-UA-Compatible "IE=edge";
}
angular.json

 "outputPath": "dist/heroes",
现在一切都好了。希望其他人会觉得这很有用