小编Abd*_*had的帖子

反应 cookie 与通用 cookie 对比反应 cookie

我正在使用 JWT 创建和验证令牌并将令牌存储在 cookie 中。(反应前端 vs Nodejs 后端)

我对 react-cookie 与通用 cookie 和 react-cookie 的使用感到困惑。

这些有什么区别,在后端和前端设置 cookie 有什么区别?

cookies node.js jwt reactjs

13
推荐指数
1
解决办法
2379
查看次数

使用 Async/Await 的 Nodemailer 电子邮件确认

我正在使用 nodemailer 发送邮件。我需要知道邮件是否已发送,然后更新我的数据库,但邮件是在传输器中发送的(我认为它不会返回承诺),这需要时间,因此即使发送了邮件,返回也始终是错误的.

这是我从其他路由调用的邮件发送文件

//mail_file.js
//imports

sendmail= async(req)=>{
      let transporter = nodemailer.createTransport({
           //settings
      });
      var mailOptions = {
          //mailoptions
      };
      let resp=false;
      await transporter.sendMail(mailOptions, function(error, info){
          if (error) {
              console.log("error is "+error);
              resp =false;
           } 
          else {
              console.log('Email sent: ' + info.response);
              resp=true;
           }
          });
     return resp
 }

module.exports = sendmail;
Run Code Online (Sandbox Code Playgroud)

这是我称之为的路线:

//imports including the mail_file.js

//somepath.js
router.post('/somepath',(req,res,next)=>{
      sendresetmail=async()=>
            {
                parameters={
                         //some email parameters
                }
                return await sendmail(params);

            }   
       sendmail()
       .then(response=>{
            //response is always false even when the mail is …
Run Code Online (Sandbox Code Playgroud)

node.js promise async-await nodemailer

10
推荐指数
2
解决办法
2万
查看次数

无法安装jspdf 1.5.3

我需要将html转换为pdf,而我正在使用jspdf 1.5.2。它显示错误“无法读取未定义的属性'charAt'(与html2canvas一起使用)。

当我尝试安装jspdf 1.5.3时,我得到了:

npm ERR! path git
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn git
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/eligrey/FileSaver.js.git
npm ERR! enoent 
npm ERR! enoent 
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
Run Code Online (Sandbox Code Playgroud)

我已经阅读了其他主题,但没有一个对您有帮助。

javascript npm html2canvas jspdf reactjs

6
推荐指数
2
解决办法
1927
查看次数

无法使用 url 通过 nginx 在 React 中导航

我正在使用 nginx(反应前端)提供静态文件。我为每个页面使用了不同的网址,例如 /login /user /home 。

我的 nginx 不会将这些重定向到我的 index.html 文件。

我做了一些更改,现在我也无法访问我的主页。它返回无法获取/。

这是我的 nginx.conf 文件。我在 Windows 上运行它。我的index.html 位于build 文件夹内。如何让我的nginx使用reactjs中的Router和Link,以便我可以通过引用链接或通过导航栏获取页面?

worker_processes  5;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;


    server {
        listen   80;
        server_name  ip;

        location / {
            root   /Users/username/projectfolder/build;    
            index  index.html index.htm;
            try_files $uri $uri/ index.html;
            proxy_pass http://ipaddress:portnumber;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
         }
     }
 }
Run Code Online (Sandbox Code Playgroud)

更新:

我尝试过以下配置

server {
        listen some_port;
        server_name some_ip; …
Run Code Online (Sandbox Code Playgroud)

nginx reactjs nginx-location nginx-config

5
推荐指数
1
解决办法
2405
查看次数

React应用无法在Internet Explorer 11中运行

我的react应用无法在Internet Explorer 11上运行。在边缘和Chrome上运行正常。

我已经创建了很多文件,但我不认为我可以尝试npx create-react-app。(如其他问题中所指出的那样)

我已经将其包含在两个index.js文件中,但无法正常工作。

import 'react-app-polyfill/ie11';
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

这是我得到的错误:

我查看了链接,他们要求解决方括号错误,但是当我看到代码时没有问题。

这是我的package.json文件:

{
      "name": "insurance_automation",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "axios": "^0.18.0",
        "babel-polyfill": "^6.26.0",
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.19.0",
        "config": "^3.1.0",
        "cors": "^2.8.5",
        "express": "^4.17.1",
        "jsonwebtoken": "^8.5.1",
        "multer": "^1.4.1",
        "mysql2": "^1.6.5",
        "node": "^11.15.0",
        "nodemailer": "^6.2.1",
        "react": "^16.8.6",
        "react-dom": "^16.8.6",
        "react-router-dom": "^5.0.0",
        "react-scripts": "3.0.1",
        "sequelize": "^5.8.6",
        "universal-cookie": "^4.0.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "server": "nodemon server",
        "dev": "concurrently \"npm run server\" \"npm …
Run Code Online (Sandbox Code Playgroud)

internet-explorer node.js reactjs

3
推荐指数
1
解决办法
3550
查看次数

将pdf文件从nodejs发送给用户到reactjs

我在服务器端的文件系统中存储了 pdf 文档。

我需要让用户在他/她点击下载时下载其中之一。

问题是我知道如何将文件从 NodeJS 发送到浏览器,但这里的请求将由 ReactJS axios 请求发出。因此,当我发送文件时,响应将做出反应。如何将该pdf文件发送给用户?我是否可以使用前端代码直接访问文件系统?

当我res.sendFile(file_path)在 NodeJS 中执行后记录响应时,我在浏览器控制台中得到以下信息

在此处输入图片说明

我如何处理这个以便我可以让用户下载 pdf?

node.js reactjs

3
推荐指数
1
解决办法
4328
查看次数

如何在mockito的单元测试中传递函数中的任何UUID?

我有一个函数 func() ,它接受 UUID 作为参数。我正在做一个单元测试,我需要为传递给 func() 的任何 UUID 值返回一个特定的值。如何使它适用于任何 UUID 类型值(就像anyString()任何字符串、anyInt()任何整数等)?

我已经尝试过:

when(obj.func(any(UUID.class)).thenReturn(null);
Run Code Online (Sandbox Code Playgroud)

它给出了以下错误:

The method any(Class<UUID>) is ambiguous for the type <Test_Class_Name>

其中 Test_Class_Name 是我编写单元测试的类的名称。

func() 是一个重载函数:func(String) 和 func(UUID)

java generics junit testng mockito

3
推荐指数
1
解决办法
1298
查看次数

如何将div扩展到整个页面?

我正在尝试为我的React应用程序中的页面设置背景颜色。我想将背景色设置为扩展到整个页面的长度和宽度,但是我不能这样做,对于超出范围的表格或表格,我将高度/宽度或最小高度/最小宽度设置为100%,我得到的结果是内容较大,但内容较小时,我得到以下信息:

我要整个页面都变成蓝色。

在此处输入图片说明

这是我的css文件

.body
{
   margin:0px 0px 0px 0px;
   background-color:#4086ef;
   padding:10px;
   height:100%;
   width:100%;
}
Run Code Online (Sandbox Code Playgroud)

如果将高度设置为100vh,则会得到不想要的结果,但是内容超出页面范围。

(内容呈现是动态的,所以我不知道什么时候内容会超出范围,什么时候不会超出范围)。

编辑: 当我压缩窗口时,表格不会挤压,溢出的部分也不会跟随背景颜色,但是即使滚动时高度也不会跟随背景颜色。

html css reactjs

2
推荐指数
1
解决办法
92
查看次数