Angular 10 + NodeJS + Express-无法加载图像,但可以在本地工作

问题描述

问题

我有一个Angular项目,已部署到Linux Server + NodeJS + Express。 当我在本地运行项目时,所有图像都可以正常加载。 当我将项目上传到服务器上并访问该站点时,它将不会加载静态图像。

我的文件夹结构

Project
- dist (Angular disT Folder)
    - assets
        - images
            - logo.png
    - index.html
    - styles.css
    - etc
- config
- controllers
- node_modules
- routes
- templates
- package.json
- server.js

Server.js

这是我的server.js文件代码

// imports
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();

// Parsers
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));

// Angular disT output folder
app.use(express.static(path.join(__dirname,'dist')));

require("./routes/api.routes")(app);

// Send all other requests to the Angular app
app.get('*',(req,res) => {
    res.sendFile(path.join(__dirname,'dist/index.html'));
});

// set port,listen for requests
const PORT = process.env.PORT || 3000;

app.listen(PORT,() => {
  console.log(`Server is running on port ${PORT}.`);
});

希望有人可以帮助我!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)