小编Bar*_*son的帖子

安全cookie node.js + Heroku + CloudFlare

我看了这个答案这个答案,但没有骰子.我的问题是,当我的应用程序通过https://appname.herokuapp.com访问时,一切正常.但是当通过https://www.appname.com(CloudFlare别名为https://appname.herokuapp.com)访问时,它会崩溃.

具体来说,当用户登录时,将正确处理身份验证,但未正确设置用户会话cookie.因此,当登录用户转发到下一个屏幕时,请求将被拒绝为未经授权.

现在我在快递中这样做:

var mySession = session({
    key: "sid",
    secret: process.env.SESSIONS_SECRET,
    proxy: true,
    cookie: {
        maxAge: 86400000,
        secure: true,
    },
    store: rDBStore,
    resave: false,
    saveUninitialized: true,
    unset: 'destroy'
});

app.enable('trust proxy');
app.use(mySession);
Run Code Online (Sandbox Code Playgroud)

我在节点代码或CloudFlare设置中遗漏了什么?

cookies https heroku node.js cloudflare

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

mysql2 TypeError:f.ClientHandshake不是构造函数

我正在尝试使用mysql2连接到RDS MySQL实例.当我在本地使用包时,一切正常.但是,当我在AWS Lambda函数中使用它时,我得到了这个神秘的错误:

TypeError: f.ClientHandshake is not a constructor
at new g (/var/task/index.js:275:62824)
at new o (/var/task/index.js:275:224046)
at e.exports.getConnection (/var/task/index.js:275:218705)
at e.exports.execute (/var/task/index.js:275:220197)
at /var/task/index.js:275:372341
at new Promise (<anonymous>)
at c.execute (/var/task/index.js:275:372308)
at /var/task/index.js:357:14189
at E (/var/task/index.js:316:24416)
at Generator._invoke (/var/task/index.js:316:24204)
Run Code Online (Sandbox Code Playgroud)

知道问题是什么吗?我确信角色/安全组都已正确配置.

amazon-rds mysql2 aws-lambda node-mysql2

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

使用Jest模拟命名的导入

我有一个'notifications.js'模块,看起来像这样:

import { Notifications, Permissions } from 'expo'

export function setLocalNotification(storage = AsyncStorage) {
  return storage
    .getItem(NOTIFICATION_KEY)
    .then(JSON.parse)
    .then(data => {
      if (data === null) {
        return Permissions.askAsync(
          Permissions.NOTIFICATIONS
        ).then(({ status }) => {
          if (status === 'granted') {
            Notifications.cancelAllScheduledNotificationsAsync()
            ...etc.
Run Code Online (Sandbox Code Playgroud)

在我的测试中,我想模拟“权限”和“通知”,以便可以在notifications.spec.js中执行以下操作:

import { setLocalNotification } from './notifications'
import mockAsyncStorage from '../mock/AsyncStorage'

it('correctly cancels pending notifications', done => {
  setLocalNotification(mockAsyncStorage).then(done())
  expect(Permissions.askAsync).toBeCalled()
  expect(Notifications.cancelAllScheduledNotificationsAsync)
    .toBeCalled()
})
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用各种方法jest.mockjest.setMock但是似乎无法正常工作。如何以所需的方式模拟这些命名的导入?例如,我已经尝试过了:

jest.setMock('Permissions', () => ({
  askAsync: jest
    .fn()
    .mockImplementationOnce(() => ({ status: …
Run Code Online (Sandbox Code Playgroud)

jestjs react-native es6-modules expo

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