egg 添加 samesite=none, 出现感叹号

设置 samesite 前提是必须同时设置Secure属性(Cookie 只能通过 HTTPS 协议发送),否则无效,所以我们先配置 https

先生成ssl 证书

可以查看这里

在本地开发环境配置文件里 config.local.js
	npm i egg-cluster --save
	
	config.cluster = {
		https: {
			key: path.join(__dirname, "../private.pem"), // https 证书绝对目录
			cert: path.join(__dirname, "../file.crt"), // https 证书绝对目录
		},
	};
  	config.cookies= {
    	sameSite: 'none',
  	}

	//跨域配置
	config.cors = {
		origin: "http://www.bh-admin.com",  // 本地开发域名
		credentials: true,
		allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS",
	};
在conttroller admin.js

	async test() {
	const { ctx, app, service } = this;
	ctx.cookies.set("user-token", "123456", {
		maxAge: 1000 * 60 * 60 * 24 * 7,
		httpOnly: false,
		encrypt: true, // 是否加密
	});
		ctx.body = {};
		ctx.status = 200;
	}
啊。。。舒服了

在这里插入图片描述

访问的的时候应该会报错

net::ERR_CERT_AUTHORITY_INVALID
1,点击错误的请求链接,信任即可
2,参考地址这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值