問題タブ [connect-mongo]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - Sharing session between express apps (connect-mongodb)
so my end goal is to have multiple node apps that connect to the same database and share sessions among users. So if you log out of one app it logs you out of all of them and same goes for logging in. So this IS WORKING in my dev environment. I have two node express apps connecting to the same Mongo session database so I can log into one app and the other automatically recognizes the session and logs me in. I have since pushed this to our live CentOS server and use PM2 and Nginx for serving it. It is currently creating a new session entry for each app. Both apps use the same database for sessions and users. I can see in the live session database that there is a separate session for each app. Thus, I have to log into each app right now instead of one. This must be something to do with Nginx because this works locally.
NOTE: i'm using connect-mongodb-session
Here is my main.js file in each express app (same for both except for port #):
Here is my nginx Conf. I tried the suggestion here to add "proxy_set_header X-Forwarded-Proto $scheme":
javascript - connect-mongo: 'sessions' コレクションに書き込めないのはなぜですか?
を使用connect-mongo
してexpress-session
いますが、セッション データは期待どおりに Mongo に書き込まれています。
ただし、そのコレクションに独自のフィールドを書き込むために使用するsessions
コレクションを再利用したいと思います。connect-mongo
次のような独自のセッション モデルを定義しsessions.js
ました。
次に、サーバーファイルに次のものがあります。
本当に驚いたのは、上記の print ステートメントが更新されたセッション オブジェクトを実際にログに記録していることです。ただし、後でデータベースを検査すると、ドキュメントは更新されません。
また、まったく別のSessionsAlternative
コレクションを作成してみました。その場合、コレクションは正しく更新されます。それは解決策ですが、私が書こうとしているものは単一のセッション コレクションに属する必要があるため、概念的には最適ではありません。
これはまったく可能ですか?もしそうなら、私は何を間違っていますか?