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

时间:2019-11-05 12:29:42

标签: angular express server-side angular-universal

我在Express.js上使用A8 ssr或angular Universal,但是我不知道这是否是服务器上所有文件的正确设置,我有:

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'));

这是正确的设置吗?

1 个答案:

答案 0 :(得分: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时