问题描述
我有一个使用Nuxt.js构建的项目,我想使用express来报告asyncData方法等上的bugsnag错误。
I have a project built with Nuxt.js and I want to use express to be able to report bugsnag errors on my asyncData method etc.
我要怎么去导入那个?我想这不是npm install express --save那样简单。
How would I go to import that? I suppose is not as simple as npm install express --save.
我已经有一个用PHP编写的api,所以我不会将其用作api或其他任何东西。
I already have an api written in PHP so I would not use that as an api or anything else.
是不是太过分了?还是有必要的邪恶? :D
Is it overkill? Or is it a necessary evil? :D
推荐答案
您不需要express即可处理asyncData中的错误。要处理ssr上asyncData / fetch中的错误,您只需挂接到render:errorMiddleware。请参阅以获取有关nuxt的信息例子
You dont need express to handle errors in asyncData. To handle errors in asyncData/fetch on ssr you just need to hook into render:errorMiddleware. See sentry plugin for nuxt for example
但是它只会捕获SSR上发生的错误。不幸的是,在客户端上不会捕获任何东西(以及表示不会为客户端做任何事情)。 nuxt中对此有一个错误,请参见
But it would only catch errors that happens on SSR. On client unfortunately that wont catch anything ( as well as express wont do anything for client). There is a bug for this in nuxt see here
这篇关于在现有的Nuxt.js项目中使用Express.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!