使用express.js在服务器上为angular8 ssr服务的文件

问题描述 投票:0回答:1

我在express.js中使用A8 ssr或angular Universal,但是我不知道这是否是在我的server.ts上处理所有文件的正确设置:

app.use(express.static('public-optimized'));
app.use(express.static('public'));
app.use(express.static('files'));
app.use(express.static('/my-project/*.*'));
app.use(express.static('*.js'));
app.use(express.static('*.json'));
app.use(express.static('*.css'));
app.use(express.static('*.png'));
app.use(express.static('*.jpg'));
app.use(express.static('/assets/*.*'));

app.use(express.static('/main.js'));
app.use(express.static('/styles.css'));
app.use(express.static('/runtime.js'));
app.use(express.static('/polyfills.js'));
app.use(express.static('/vendor.js'));
app.use(express.static('/scripts.js'));

这是正确的设置吗?

angular express server-side angular-universal
1个回答
0
投票

看起来不像是正确的设置。不适合设置静态文件。

根据https://angular.io/guide/universal,您可以进行设置

// Server static files from your angular build folder
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

其中DIST_FOLDER =您的构建文件夹路径(通常是dist /文件夹中的dist/文件夹的路径)和'browser' is the name of your inner folder在执行SSR时的路径

© www.soinside.com 2019 - 2024. All rights reserved.