- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试从服务器向客户端发送一个 cookie。我获得了响应数据,但在响应 header 中没有看到“set-cookie”
我的 Apollo 服务器配置:
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req, connection, res }) => ({
dummyModels: dummyModels,
models: models,
req,
connection,
res,
currentUser: dummyModels.users[2],
dummyUsers: dummyModels.dummyUsers,
}),
});
app.use(cors({
credentials: true,
origin: 'http://localhost:3000',
// preflightContinue: true,
}));
login: async (parent, args, context) => {
const _include_headers = function(body, response, resolveWithFullResponse) {
return {'headers': response.headers, 'data': body};
};
const loginRequestOptions = {
method: 'POST',
uri: 'http://localhost:3000/incorta/authservice/login',
qs: {
// access_token: 'xxxxx xxxxx', // -> uri + '?access_token=xxxxx%20xxxxx'
user: args.input.username,
pass: args.input.password,
tenant: args.input.tenantName,
},
transform: _include_headers,
json: true // Automatically parses the JSON string in the response
};
const loginResponse = await request(loginRequestOptions);
console.log(loginResponse);
context.res.cookie(
'JSESSIONID',
tough.Cookie.parse(loginResponse.headers['set-cookie'][0]).value,
{
// expires : new Date(Date.now() + 9999999),
// path: '/incorta/',
// HttpOnly: false,
// maxAge: 1000 * 60 * 60 * 24 * 99, // 99 days
},
);
context.res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
return loginResponse.data;
},
const httpLink = createHttpLink({
uri: 'http://172.16.16.130:4000/graphql',
credentials: 'include',
fetchOptions: {
credentials: 'include',
},
});
const wsLink = new WebSocketLink({
uri: 'ws://172.16.16.130:4000/graphql',
options: {
reconnect: true,
connectionParams: {
headers: {
'x-user-header': localStorage.getItem('userObject'),
},
},
}
});
const terminatingLink = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
);
const link = ApolloLink.from([terminatingLink]);
const cache = new InMemoryCache();
export const client = new ApolloClient({
link,
cache,
});
最佳答案
您可以使用 apollo-server-plugin-http-headers用于在 apollo 服务器中设置 cookie 的包。
在您的解析器中使用就像这样简单:
context.setCookies.push({
name: "cookieName",
value: "cookieContent",
options: {
domain: "example.com",
expires: new Date("2021-01-01T00:00:00"),
httpOnly: true,
maxAge: 3600,
path: "/",
sameSite: true,
secure: true
}
});
关于express - res.cookie 不适用于 apollo-server-express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55302412/
我正在使用 express并试图通过管道传输 req到远程服务器进行处理,然后通过 res 将结果通过管道传回客户端.它运行良好,但有时我认为 res由 connect-timeout 的操作结束,导
我正在尝试使用 fetch 进行简单的发布请求: const headers = new Headers({ Accept: 'application/json', 'Content-Type
我偶然发现了一个代码示例 here .引起我注意的行(跳过所有其他行): { ... void *res; ... s = pthread_join(tinfo[tnum].thread_id
我有一个 NodeJS 代码,使用请求模块向服务器发出请求。如果我使用“http.request”,代码工作正常,但在 res.on() 上显示错误使用请求来调用电话。以下是显示错误的部分: cons
我想知道这两种不同的方法在 expressjs 中是否相同? res.statusCode = 500; return res.json({ status: "error" }); 或者 r
我正在尝试在 Node.js 中制作简单的 ftp 客户端。一切正常,但我不知道如何在我的 Jade 模板中编写“singleFile.name”。 app.post('/ftp/login', fu
在frameworks/base下有这个xml文件。 /frameworks/base/core/res/res/layout/simple_dropdown_item_2line.xml 如何在我自
我是 odoo v8 的新手,我无法理解 res_partner 和 res_users 表之间的关系以及与 hr_employee 表之间的关系,它们都相关吗? 最佳答案 res.partner之间
我正在开发一个用于用户登录的小部件。基本上,当他们输入有效的帐户详细信息时,我希望它呈现相同的页面(使用 Handlebars )并声明“帐户已成功验证”之类的内容,然后 3 秒后重定向用户。 这是我
我有这种形式的数据 [ { device_id: '12335', timestamp: '2018-05-14T08:31:23.000Z', temperatur: 21,
我是 android 开发的新手,您可能会从我的问题中看出这一点。我发现我有一个 res/menu 文件夹和一个 res/layout 文件夹。它们都包含每个 Activity 的 XML 文件。但是
当我尝试按照指南中的说明在 res/menu 中创建新的菜单资源文件时,该文件夹不存在。 res/xml 也不是。有人可以告诉我如何解决这个问题吗?我尝试创建文件夹,但它不允许我这样做 最佳答案 如果
调用有什么区别: res.flushBuffer(); 对比 res.getOutputStream().flush(); 这些方法是否刷新相同的缓冲区? 如果是这样,你能告诉我这个缓冲区是如何由
为什么以下不起作用? res.send({ successMessage: 'Task saved successfully.' }); res.redirect('/'); 我基本上需要 A
我正在尝试确定是否可以同时调用 res.send(data) 和 res.render('reports')。 为了进一步详细解释,当我路由到“/reports”时,首先在我的服务器端我对返回 jso
app.get('/p/:tagId', function(req, res) { res.send("tagId is set to " + req.param("tagId")); }); 上
我在使用express.js 时遇到一些问题。我想在第一次请求时渲染我的模板,然后从路由中获取一些数据。我的路由如下所示: app.use(function (req, res, next) { r
我想根据屏幕尺寸加载 dimens.xml,但无论屏幕尺寸如何都使用相同的颜色。 我有以下目录结构 res res/values colors.xml res/values-small d
我有一张图片,rectangle.png。它的尺寸是 75x197。它位于 res/drawable 和 res/drawable-xhdpi。它在像这样的网格布局中显示了很多次(截图来自 Nexus
我很好奇返回响应和仅创建响应的区别。 我见过大量使用 return res.status(xxx).json(x) 的代码示例和res.status(xxx).json(x) . 谁能详细解释一下两者
我是一名优秀的程序员,十分优秀!