Skip to content

Commit 929cc2d

Browse files
committed
Add pysocks dependency and update MongoDB settings to support proxy configuration
1 parent 2044950 commit 929cc2d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

backend/api/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import logging
3+
import urllib.parse
34
import firebase_admin
45

56
from flask import Flask, request
@@ -64,7 +65,21 @@ def create_app():
6465
password = os.environ.get("MONGO_PASSWORD")
6566
db = os.environ.get("MONGO_DB")
6667
host = os.environ.get("MONGO_HOST")
67-
app.config["MONGODB_SETTINGS"] = {"db": db, "host": host % (user, password, db)}
68+
mongodb_settings = {"db": db, "host": host % (user, password, db)}
69+
70+
fixie_url = os.environ.get("FIXIE_SOCKS_HOST")
71+
if fixie_url:
72+
if "://" not in fixie_url:
73+
fixie_url = "socks5://" + fixie_url
74+
parsed = urllib.parse.urlparse(fixie_url)
75+
mongodb_settings.update({
76+
"proxyHost": parsed.hostname,
77+
"proxyPort": parsed.port,
78+
"proxyUsername": parsed.username,
79+
"proxyPassword": parsed.password,
80+
})
81+
82+
app.config["MONGODB_SETTINGS"] = mongodb_settings
6883
# app.config["MONGODB_SETTINGS"] = {
6984
# "db": "mentee",
7085
# "host": "localhost",

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ python-dotenv = "1.0.0"
2424
WTForms-JSON = "0.3.5"
2525
sendgrid = "6.9.7"
2626
pymongo = "4.6.0"
27+
pysocks = ">=1.7.1"
2728
pandas = "1.5.3"
2829
XlsxWriter = "3.0.8"
2930
firebase-admin = "6.1.0"

backend/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ pyjwt==2.6.0
322322
pymongo==4.6.0
323323
# via
324324
# backend (pyproject.toml)
325+
pysocks==1.7.1
326+
# via
327+
# backend (pyproject.toml)
325328
# mongoengine
326329
pyparsing==3.0.9
327330
# via

0 commit comments

Comments
 (0)