小编use*_*061的帖子

使用 Express.JS + Nginx 设置 cookie 时遇到问题

我正在将前端与后端存储库分离。为此,我将服务器托管在家庭网络上的个人 Raspberry Pi 3 上。我的前端由 Netlify 托管。我遇到了一个问题,尽管我可以在 Postman 中看到 cookie 设置,但我无法使用 Express.Js 在客户端上设置 cookie。

我当前的设置如下:

FE (Netlify - example.com) -> Nginx (Reverse Proxy - api.example.com) -> Node.js (Express - listening for http)
Run Code Online (Sandbox Code Playgroud)

我无法登录使用 Express-Session 进行会话的应用程序。我可以发布登录信息,但没有看到响应中设置了 cookie。话虽如此,我在 Heroku 上工作了(FE + BE 在同一个仓库上)

我尝试了很多方法来使其正常工作,但都失败了。

我尝试过的一些解决方案是:

  • app.set('信任代理', 1)
  • 快速会话({代理:true})
  • 将 cookie 域设置为.example.com
  • 为我的域启用 CORS
  • 设置要使用的 Axios{ withCredentials: true }
  • proxy_set_header X-Forwarded-Proto https;

NGinx 配置

server {
        root /var/www/example-backend;
        server_name api.example.com;
        location / {
                proxy_pass http://127.0.0.1:3000;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For …
Run Code Online (Sandbox Code Playgroud)

javascript nginx node.js express express-session

6
推荐指数
0
解决办法
1658
查看次数

无法从类中迭代列表

我目前正在做一个"拼写检查"问题.

我已经创建了一个包含字典的列表.

现在我想看看是否word在列表中.

我是新手使用Python的类,所以我可能错过了一些小东西.

最近的错误已经发生 "TypeError: 'list' object cannot be interpreted as an integer"

这是代码的摘录.

class SpellChecker():

    def __init__(self, file_name):
        self.__infile = open(file_name,'r')
        self.word_list = []
        self.temp = self.__infile.readline().strip("\n")
        while self.temp != "":
            self.word_list.append(self.temp)
            self.temp = self.__infile.readline().strip("\n")
        self.__infile.close()

    def spellcheck_word(self, word):
        self.word = word.strip(string.punctuation).lower()
        self.list = self.word_list
        for i in range(self.list):
            if self.word == self.list[i]:
                return True
            else:
                return False
def main():
    test = SpellChecker("dictionary.txt")
    print(test.spellcheck_word("apple"))
Run Code Online (Sandbox Code Playgroud)

python

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

MongoDB-检查集合中是否存在多个字段

我正在寻找一种方法来查看collection中是否已经存在两个字段。我一直在阅读文档,但它们似乎并没有太大帮助。我已经看到可以使用$ exist,但是可以同时比较多个字段吗?

我将如何实现这一目标?

我有这样的收藏

{userId: ObjectId("57840667f862724c0f736a69"), artId: ObjectId("5783e368b30fb4482ba390eb")}
Run Code Online (Sandbox Code Playgroud)

我想检查一下此集合是否包含两个

userId:ObjectId("57840667f862724c0f736a69") && artId: ObjectId("5783e368b30fb4482ba390eb") 
Run Code Online (Sandbox Code Playgroud)

mongodb

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

标签 统计

express ×1

express-session ×1

javascript ×1

mongodb ×1

nginx ×1

node.js ×1

python ×1