Ananthakr1shnan commited on
Commit
c8fb59f
·
1 Parent(s): 356ac4f

Updated files

Browse files
Files changed (4) hide show
  1. app.py +21 -7
  2. data/active_sessions.json +3 -3
  3. new.py +0 -0
  4. src/static/js/main.js +6 -2
app.py CHANGED
@@ -92,24 +92,38 @@ security = HTTPBearer(auto_error=False)
92
  # Settings for Hugging Face Spaces: use /tmp dirs
93
  class Settings:
94
  def __init__(self):
 
 
 
95
  self.server = type('ServerSettings', (), {
96
- 'debug': False,
97
- 'host': '0.0.0.0',
98
- 'port': int(os.environ.get('PORT', 7860)) # Default to 7860 for HF Spaces
99
  })()
100
  self.security = type('SecuritySettings', (), {
101
  'cors_origins': ["*"],
102
  'cors_methods': ["*"],
103
  'cors_headers': ["*"]
104
  })()
 
105
  def get_static_dir(self):
106
- return "/tmp/researchmate/static"
 
 
 
107
  def get_templates_dir(self):
108
- return "src/templates" # Templates can remain in src
 
 
109
  def get_upload_dir(self):
110
- return "/tmp/researchmate/uploads"
 
 
 
111
  def get_logs_dir(self):
112
- return "/tmp/researchmate/logs"
 
 
113
 
114
  settings = Settings()
115
 
 
92
  # Settings for Hugging Face Spaces: use /tmp dirs
93
  class Settings:
94
  def __init__(self):
95
+ # Detect if running in Hugging Face Spaces (PORT is set and not a typical local port)
96
+ port_env = os.environ.get('PORT')
97
+ self.is_spaces = port_env is not None and port_env not in ['8000', '5000', '8080']
98
  self.server = type('ServerSettings', (), {
99
+ 'debug': not self.is_spaces,
100
+ 'host': '127.0.0.1',
101
+ 'port': int(port_env) if port_env else 8000 # Default to 8000 for local
102
  })()
103
  self.security = type('SecuritySettings', (), {
104
  'cors_origins': ["*"],
105
  'cors_methods': ["*"],
106
  'cors_headers': ["*"]
107
  })()
108
+
109
  def get_static_dir(self):
110
+ if self.is_spaces:
111
+ return "/tmp/researchmate/static"
112
+ return "src/static"
113
+
114
  def get_templates_dir(self):
115
+ # Templates can remain in src for both
116
+ return "src/templates"
117
+
118
  def get_upload_dir(self):
119
+ if self.is_spaces:
120
+ return "/tmp/researchmate/uploads"
121
+ return "uploads"
122
+
123
  def get_logs_dir(self):
124
+ if self.is_spaces:
125
+ return "/tmp/researchmate/logs"
126
+ return "logs"
127
 
128
  settings = Settings()
129
 
data/active_sessions.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "admin_user": {
3
- "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW5fdXNlciIsInVzZXJuYW1lIjoiYWRtaW4iLCJleHAiOjE3NTI2MTI4NjR9.-4rWv6qNOaSp9kup3AjqbwhC_h5P6anYhxP6OfYoBWU",
4
- "created_at": "2025-07-15T18:24:24.155119",
5
- "last_activity": "2025-07-15T18:26:51.425464"
6
  }
7
  }
 
1
  {
2
  "admin_user": {
3
+ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW5fdXNlciIsInVzZXJuYW1lIjoiYWRtaW4iLCJleHAiOjE3NTI2MTQwMzZ9.ymVeZ3z0Qiap57XjE2u8II_EXexLH49oM3shT7lXfJ0",
4
+ "created_at": "2025-07-15T18:43:56.569611",
5
+ "last_activity": "2025-07-15T18:43:58.764999"
6
  }
7
  }
new.py ADDED
File without changes
src/static/js/main.js CHANGED
@@ -21,8 +21,12 @@ function setAuthToken(token) {
21
  localStorage.setItem('authToken', token);
22
  localStorage.setItem('tokenTimestamp', Date.now().toString());
23
 
24
- // Set cookie with HttpOnly equivalent behavior
25
- document.cookie = `authToken=${token}; path=/; SameSite=Strict; Secure=${location.protocol === 'https:'}`;
 
 
 
 
26
 
27
  // Reset activity tracking
28
  lastActivityTime = Date.now();
 
21
  localStorage.setItem('authToken', token);
22
  localStorage.setItem('tokenTimestamp', Date.now().toString());
23
 
24
+ // Set cookie with Secure flag only if using HTTPS
25
+ let cookie = `authToken=${token}; path=/; SameSite=Strict`;
26
+ if (location.protocol === 'https:') {
27
+ cookie += '; Secure';
28
+ }
29
+ document.cookie = cookie;
30
 
31
  // Reset activity tracking
32
  lastActivityTime = Date.now();