如您所知,我们可以轻松地使用样式加载器将样式添加到我们的react项目中,但是该窗口在服务器端渲染中不可用,那么如何使用样式加载器(或在SSR项目中替代样式加载器)?
当我使用style-loader时,它按预期返回此错误:
.../public/server.js:866
return window && document && document.all && !window.atob;
^
ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud) reactjs webpack webpack-style-loader server-side-rendering ssr
众所周知,我们必须在 Express 应用程序中返回响应,以避免“将标头发送到客户端后无法设置标头”错误。但是,在下面的代码中,我尝试返回响应,但它返回到我们的路由器并导致提到的错误。如何在函数中直接返回响应?
router.post("/admins", async function (req, res) {
var newAdminObj = await newAdminObjectDecorator(req.body, res);
var newAdmin = new Admins(newAdminObj)
newAdmin.save(function (err, saveresult) {
if (err) {
return res.status(500).send();
}
else {
return res.status(200).send();
}
});
});
// the function
var newAdminObjectDecorator = async function (entery, res) {
// doing some kinds of stuff in here
// if has errors return response with error code
if (err) {
// app continues after returning the error header response
return …Run Code Online (Sandbox Code Playgroud) 我有一个名为Projects的集合;在此集合中,我有一个项目货币字段和一个价格金额字段。
在 Express 搜索路线中,我有 2 个变量,称为USDamount和EURamount。我的问题是,当文档的货币为“USD”时,如何按 USDamount 搜索匹配定价的项目;当文档的货币为“EUR”时,如何按 EURamount 搜索,对于其他货币依此类推(这意味着我需要一个 switch/case 而不是 if /别的)?