如何将一个路由的 Http 字段 "withCredentials" 更改为 FALSE
How to change one route's Http field "withCredentials" to FALSE
作为我现在正在构建的新注册表的一部分,我需要列出所有可用的列表 "Institutions",以便用户可以告诉我他们是哪一个注册。
在后端策略中,我将控制器操作设置为 public:
InstitutionController: {
// Some other policies I edited out
'all': true
},
控制器是您的标准 "get all of objects" 控制器操作。
all: function (req, res) {
Institution
.find()
.exec(function (err, institutions) {
if (err) { return res.json(err.status, err); }
return res.json(institutions);
});
},
所以在 AngularJS 前端,我应该能够在我的控制器中使用 Institutions.all()
甚至在用户登录之前。情况就是这样,但是在后端 passport
正在尝试序列化和反序列化(不存在的)用户,然后再执行此方法。
因此,我在 API 控制台收到此错误:
error: Server Error:
error: Error: Failed to deserialize user out of session
at pass (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:340:19)
at deserialized (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:345:7)
at bound (/home/zacharyhustles/texasca-API/node_modules/lodash/dist/lodash.js:957:21)
.......
当我尝试执行此控制器方法时,如何避免护照序列化和反序列化用户 InstitutionController.all()
?
更新
问题是此请求正在发送 withCredentials: true
,因为在我的应用程序的 app.js
文件中,我将带有 restangular 的 HTTP 字段的默认设置设置为 true
:
app.js
RestangularProvider.setDefaultHttpFields({ withCredentials: true });
如果我将其设置为 "false",问题就解决了。但是,我确实希望发送到服务器的大多数请求 "withCredentials" 所以我需要一种方法来为这个请求设置例外。如您所见,我在我的应用程序中使用了 Restangular,所以希望我能以 Restangular 的方式做到这一点。有人知道怎么做吗?
最好的,
扎克
我明白了。
Restangular 添加了一种为每个请求设置自定义 http 字段的方法。我已经为这个请求手动设置了 withCredentials : false
。我修改后的后端调用现在看起来像这样:
return Restangular.all('institutions')
.withHttpConfig({ withCredentials: false}).getList();
之前。
return Restangular.all('institutions').getList();
作为我现在正在构建的新注册表的一部分,我需要列出所有可用的列表 "Institutions",以便用户可以告诉我他们是哪一个注册。
在后端策略中,我将控制器操作设置为 public:
InstitutionController: {
// Some other policies I edited out
'all': true
},
控制器是您的标准 "get all of objects" 控制器操作。
all: function (req, res) {
Institution
.find()
.exec(function (err, institutions) {
if (err) { return res.json(err.status, err); }
return res.json(institutions);
});
},
所以在 AngularJS 前端,我应该能够在我的控制器中使用 Institutions.all()
甚至在用户登录之前。情况就是这样,但是在后端 passport
正在尝试序列化和反序列化(不存在的)用户,然后再执行此方法。
因此,我在 API 控制台收到此错误:
error: Server Error:
error: Error: Failed to deserialize user out of session
at pass (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:340:19)
at deserialized (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:345:7)
at bound (/home/zacharyhustles/texasca-API/node_modules/lodash/dist/lodash.js:957:21)
.......
当我尝试执行此控制器方法时,如何避免护照序列化和反序列化用户 InstitutionController.all()
?
更新
问题是此请求正在发送 withCredentials: true
,因为在我的应用程序的 app.js
文件中,我将带有 restangular 的 HTTP 字段的默认设置设置为 true
:
app.js
RestangularProvider.setDefaultHttpFields({ withCredentials: true });
如果我将其设置为 "false",问题就解决了。但是,我确实希望发送到服务器的大多数请求 "withCredentials" 所以我需要一种方法来为这个请求设置例外。如您所见,我在我的应用程序中使用了 Restangular,所以希望我能以 Restangular 的方式做到这一点。有人知道怎么做吗?
最好的, 扎克
我明白了。
Restangular 添加了一种为每个请求设置自定义 http 字段的方法。我已经为这个请求手动设置了 withCredentials : false
。我修改后的后端调用现在看起来像这样:
return Restangular.all('institutions')
.withHttpConfig({ withCredentials: false}).getList();
之前。
return Restangular.all('institutions').getList();