我将我的节点快速服务器投入生产。在开发中,express-session 运行良好(它使用 MemoryStore 将会话存储到 cookie 中)。但是现在每次刷新或发出请求时,它都会在 MongoStore 中创建一个新的会话 ID。此外,它不再在浏览器中创建 cookie(idk 是好事还是坏事)
关于这个主题的大多数 StackOverflow 查询都告诉我去做我已经做过的事情,所以没有帮助
这是我的快递和会话设置:
using System;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ConsoleApp2
{
public class Program
{
[Benchmark]
public void NotePad()
{
string path = @"..\..\..\first_million_prime_number\primes1.txt";
var sr = new StreamReader(path, Encoding.Default);
List<int> numbers = new List<int>();
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Length == 0) continue;
for (int i = 0; i < 80; i += 10)
numbers.Add(Convert.ToInt32(line.Substring(i, 10)));
}
sr.Close();
}
static void Main(string[] args)
{
BenchmarkRunner.Run<Program>();
}
}
}
可能有助于解决此问题的其他信息:前端位于单独的域中,上述服务器位于 Heroku 上,而数据库位于 MongoDB 云中。
答案 0 :(得分:0)
原来我缺少的是设置中的 app.set('trust proxy', 1)
和会话中间件中的 sameSite: 'none'
中的 cookie: {}
。