小编NL3*_*294的帖子

如何将 api 路由放入 Next.js 的新应用程序文件夹中?

我在以下位置有一个测试 API:pages\api\accounts\login.js。我正在学习新app文件夹,这仍然是 Next.js 中的一个实验性功能(截至今天)。

是否可以将我的登录脚本移至该app文件夹中?我尝试移动/重命名为app\api\accounts\login\pages.js,但是当我这样做时:

async function handler(req, res) {
  console.log(res);
}
export default handler;
Run Code Online (Sandbox Code Playgroud)

我使用的网址是:http://localhost:3000/api/accounts/login。我得到:

服务器错误

错误:找不到页面的模块:/api/accounts/login

我还尝试将其移动到:app/api/accounts/login/page.js。但我得到了同样的错误。

javascript reactjs next.js

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

你可以在 window.open() 中使用 rel=opener 吗?

我知道你可以在 window.open 中使用“noopener”,它明确地告诉你的浏览器禁止子窗口访问父窗口。这应该具有在超链接中使用 rel="noopener" 的效果。

但是,Chrome 88 很快(2021 年?)会将“noopener”设为默认设置。

那么有没有办法做相反的事情,并将其明确设置为“opener”?这样子窗口就可以访问父窗口了吗?我希望在它与最新的 Chrome 断开之前修复我的链接。

我假设它是下面的代码?我不确定在下一版 Chrome 发布之前我会如何测试。但我也不想等到我的链接与下一个版本断开后才进行此更改。

window.open(url,'_blank','toolbar=1,menubar=1,location=1,status=1,scrollbars=1,opener')    
Run Code Online (Sandbox Code Playgroud)

或者

window.open(url,'_blank','toolbar=1,menubar=1,location=1,status=1,scrollbars=1', 'opener')
Run Code Online (Sandbox Code Playgroud)

javascript rel window.open

7
推荐指数
1
解决办法
1132
查看次数

如何让 Visual Studio Code 使用不同的 Python 解释器?

我是 VS Code/Python 的新手,我正在尝试让 VSCode 运行特定版本的 Python(似乎我安装了多个版本)。

我尝试了以下代码:

import sys
print(sys.version)
Run Code Online (Sandbox Code Playgroud)

当我运行文件时,出于某种原因,它显示:

  3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul  5 2016, 11:45:57) [MSC v.1900 32 bit (Intel)]
Run Code Online (Sandbox Code Playgroud)

我尝试了以下操作:在 VSCode 的最底部,我单击 Python 版本,然后单击“Python 3.7.3 64 位”,但是当我重新运行代码时,它仍然显示“3.5​​.2 |Anaconda ……”

我也尝试检查设置,它显示:

  Python: Python Path
    C:\Users\[MY_USE_NAME]\AppData\Local\Programs\Python\Python37-32\python.exe
Run Code Online (Sandbox Code Playgroud)

我还尝试在命令中键入“python”,但它仍然显示“Python 3.5.2”。

知道我做错了什么吗?我对 VS Code 很陌生,所以希望它很简单。

截屏

python visual-studio-code pythoninterpreter vscode-settings

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

在next-auth中,如何在服务器端获取userID(nextjs 13应用程序目录)

我在用着:

    nextJS: 13.1.6
    nextAuth 4.19.2
Run Code Online (Sandbox Code Playgroud)

我正在使用新的 app/ 目录,该目录仍处于测试阶段。

我的问题是我试图检索页面中有关用户的信息,然后根据该信息执行逻辑。例如,使用用户 ID,并从数据库中获取额外信息(然后在服务器端预渲染页面)。

在 [..nextauth.js] 中,我在 jwt 和会话回调中添加了额外的信息,如下所示:

      callbacks: {
        async jwt({token, user}) {
      
           if (user?.id) {
               token.id = user.id
           }
           if (user?.userName) {
               token.userName = user.userName;
           }

          if (user?.fullname) {
            token.fullname = user.fullname;
          }

                      
           return token
        },
        async session({session, token, user}) {
            session.userID = token.id;
            session.userName = token.userName;
            
            session.fullname = token.fullname;

            //I also tried it this way, according to the docs at:
            //  https://next-auth.js.org/configuration/callbacks
            session.user.userID = token.id;
            session.user.fullname = token.fullname;

            return session; …
Run Code Online (Sandbox Code Playgroud)

next.js next-auth

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

你把_app.js放在app目录的哪里

next-auth(版本 4)的文档表明我们需要将服务提供者放入:

pages/_app.js
Run Code Online (Sandbox Code Playgroud)

我正在关注以下示例: https: //next-auth.js.org/getting-started/example

如果我使用实验性应用程序目录而不是 nextjs 13 中的页面目录,我们应该将 _app.js 文件放在哪里?

authentication server-side-rendering next.js next-auth next.js13

4
推荐指数
1
解决办法
1673
查看次数

在c#中,无法抑制进程的每一行

我正在尝试将进程的输出读取为字符串.由于某种原因,它看起来像输出中间的一行似乎输出(即,它显示在屏幕上,而不是保存到字符串).

string strOutput = "";
Process process = new Process();

process.StartInfo.FileName = "nslookup";
process.StartInfo.Arguments = "-type=mx uic.edu";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();

strOutput = process.StandardOutput.ReadToEnd();

process.WaitForExit();

Console.WriteLine("xxxxxxxxxxxxxxxxxxx");
Console.WriteLine(strOutput);
Console.WriteLine("yyyyyyyyyyyyyyyyyyy");
Run Code Online (Sandbox Code Playgroud)

我得到的输出看起来像这样:

Non-Authoritative answer:
xxxxxxxxxxxxxxxxxxxx
Server: aaa.myserver.com
Address: 111.222.111.222

uic.edu MX preference = 10, mail exchanger - ...
...
yyyyyyyyyyyyyyyyyyyy
Run Code Online (Sandbox Code Playgroud)

当我通过命令行运行命令时,"非权威答案:"在"地址:..."之后出现

有人可以解释为什么输出它,而不是作为字符串的一部分存储?我可能错过了一些明显的东西,但我很难过.

谢谢

c# nslookup redirectstandardoutput

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