A secure Flask server with JWT authentication, user management, and both API and HTML serving capabilities.
Clone or navigate to the repository:
cd c:\Users\Sovr6\OneDrive\Desktop\ishield-server
Create a virtual environment (recommended):
python -m venv venv
.\venv\Scripts\Activate.ps1
Install dependencies:
pip install -r requirements.txt
Configure environment variables (optional):
Create a .env file in the root directory:
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-key-here
DEBUG=False
PORT=5000
Run the server:
python app.py
This repo includes a production-friendly Docker setup:
eventlet worker (required for Flask-SocketIO).instance/ (local vector store files), and uploads/.Ensure Docker Desktop is installed and running.
Start the stack:
docker compose up --build
This repo defaults to CPU-only PyTorch wheels to keep the Docker image smaller.
There are two separate things you might want:
Those map to:
USE_CUDA=True (controls which PyTorch wheels are installed during docker build).cuda Compose profile (runs the web-cuda service, which requests GPUs).docker compose up --build
PowerShell:
$env:COMPOSE_PROFILES = "cuda"
$env:USE_CUDA = "True"
docker compose up --build
bash/zsh:
COMPOSE_PROFILES=cuda USE_CUDA=True docker compose up --build
If you only set USE_CUDA=True without the profile, Compose will still run the normal web service (no GPU request), but the image will contain CUDA wheels:
USE_CUDA=True docker compose up --build
This can be useful for CI/build testing, but for real GPU access you typically want the cuda profile.
TORCH_INDEX_URL.
TORCH_INDEX_URL=https://download.pytorch.org/whl/cu118USE_CUDA=True is https://download.pytorch.org/whl/cu121Edit environment variables in docker-compose.yml (recommended for local docker testing) or inject them via your deployment platform.
Important env vars:
FLASK_ENV=production (switches config.py into production behavior)DATABASE_URL=postgresql+psycopg2://... (SQLAlchemy connection string)SECRET_KEY and JWT_SECRET_KEY (set real secrets in production)Recent changes (important for deployments):
POST /auth/register always creates role=user. Any role field in the request is ignored.innerHTML)./vision connections require a valid API key (X-API-Key header or ?api_key= query param). Unauthenticated clients are disconnected.VISION_ENCRYPTION_KEY must be set or the server will fail fast.get_key endpoint.CORS_ALLOWED_ORIGINS to a comma-separated allowlist (example: https://your-ui.example.com,http://localhost:3000).* for convenience.CORS_ALLOWED_ORIGINS.MAX_UPLOAD_MB (default 10). Flask uses this to reject overly large requests.API key behavior:
POST /auth/api-keys returns api_secret once at creation time.GET /auth/api-keys no longer returns api_secret (it only returns api_key and whether a secret exists).If you have committed real API keys or tokens into .env, rotate them and remove them from version control. For safety, .env is ignored by .dockerignore so it won't be baked into Docker images.
POST /auth/register - Register a new user
{
"username": "user123",
"email": "user@example.com",
"password": "SecurePass123"
}
POST /auth/login - Login and get JWT token
{
"username": "user123",
"password": "SecurePass123"
}
POST /auth/refresh - Refresh access token (requires refresh token)
GET /auth/me - Get current user info (requires JWT token)
POST /auth/logout - Logout user
GET /api/status - Check API status (public)
GET /api/protected - Protected endpoint example (requires JWT token)
GET /api/users - Get all users (requires JWT token)
// Register
const response = await fetch('http://localhost:5000/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'newuser',
email: 'user@example.com',
password: 'SecurePass123'
})
});
const data = await response.json();
const token = data.access_token;
// Access protected endpoint
const protectedResponse = await fetch('http://localhost:5000/api/protected', {
headers: {
'Authorization': `Bearer ${token}`
}
});
import requests
# Register
response = requests.post('http://localhost:5000/auth/register', json={
'username': 'newuser',
'email': 'user@example.com',
'password': 'SecurePass123'
})
token = response.json()['access_token']
# Access protected endpoint
headers = {'Authorization': f'Bearer {token}'}
protected_response = requests.get('http://localhost:5000/api/protected', headers=headers)
ishield-server/
βββ app.py # Main Flask application
βββ config.py # Configuration settings
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ src/
β βββ auth.py # Authentication blueprint
β βββ api.py # API blueprint
β βββ models.py # Database models
β βββ vision/ # Your existing vision modules
βββ templates/ # HTML templates
β βββ index.html
β βββ login.html
β βββ register.html
β βββ dashboard.html
βββ static/ # Static files
βββ css/
β βββ style.css
βββ js/
βββ login.js
βββ register.js
βββ dashboard.js
β οΈ IMPORTANT: Before deploying to production:
SECRET_KEY and JWT_SECRET_KEY in config.py or use environment variablesDEBUG=False in productionMIT License
Feel free to submit issues and enhancement requests!
4 commits
Python
49.7%
HTML
25.4%
JavaScript
20.5%
CSS
2.7%
TypeScript
1.5%
A secure Flask server with JWT authentication, user management, and both API and HTML serving capabilities.
Clone or navigate to the repository:
cd c:\Users\Sovr6\OneDrive\Desktop\ishield-server
Create a virtual environment (recommended):
python -m venv venv
.\venv\Scripts\Activate.ps1
Install dependencies:
pip install -r requirements.txt
Configure environment variables (optional):
Create a .env file in the root directory:
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-key-here
DEBUG=False
PORT=5000
Run the server:
python app.py
This repo includes a production-friendly Docker setup:
eventlet worker (required for Flask-SocketIO).instance/ (local vector store files), and uploads/.Ensure Docker Desktop is installed and running.
Start the stack:
docker compose up --build
This repo defaults to CPU-only PyTorch wheels to keep the Docker image smaller.
There are two separate things you might want:
Those map to:
USE_CUDA=True (controls which PyTorch wheels are installed during docker build).cuda Compose profile (runs the web-cuda service, which requests GPUs).docker compose up --build
PowerShell:
$env:COMPOSE_PROFILES = "cuda"
$env:USE_CUDA = "True"
docker compose up --build
bash/zsh:
COMPOSE_PROFILES=cuda USE_CUDA=True docker compose up --build
If you only set USE_CUDA=True without the profile, Compose will still run the normal web service (no GPU request), but the image will contain CUDA wheels:
USE_CUDA=True docker compose up --build
This can be useful for CI/build testing, but for real GPU access you typically want the cuda profile.
TORCH_INDEX_URL.
TORCH_INDEX_URL=https://download.pytorch.org/whl/cu118USE_CUDA=True is https://download.pytorch.org/whl/cu121Edit environment variables in docker-compose.yml (recommended for local docker testing) or inject them via your deployment platform.
Important env vars:
FLASK_ENV=production (switches config.py into production behavior)DATABASE_URL=postgresql+psycopg2://... (SQLAlchemy connection string)SECRET_KEY and JWT_SECRET_KEY (set real secrets in production)Recent changes (important for deployments):
POST /auth/register always creates role=user. Any role field in the request is ignored.innerHTML)./vision connections require a valid API key (X-API-Key header or ?api_key= query param). Unauthenticated clients are disconnected.VISION_ENCRYPTION_KEY must be set or the server will fail fast.get_key endpoint.CORS_ALLOWED_ORIGINS to a comma-separated allowlist (example: https://your-ui.example.com,http://localhost:3000).* for convenience.CORS_ALLOWED_ORIGINS.MAX_UPLOAD_MB (default 10). Flask uses this to reject overly large requests.API key behavior:
POST /auth/api-keys returns api_secret once at creation time.GET /auth/api-keys no longer returns api_secret (it only returns api_key and whether a secret exists).If you have committed real API keys or tokens into .env, rotate them and remove them from version control. For safety, .env is ignored by .dockerignore so it won't be baked into Docker images.
POST /auth/register - Register a new user
{
"username": "user123",
"email": "user@example.com",
"password": "SecurePass123"
}
POST /auth/login - Login and get JWT token
{
"username": "user123",
"password": "SecurePass123"
}
POST /auth/refresh - Refresh access token (requires refresh token)
GET /auth/me - Get current user info (requires JWT token)
POST /auth/logout - Logout user
GET /api/status - Check API status (public)
GET /api/protected - Protected endpoint example (requires JWT token)
GET /api/users - Get all users (requires JWT token)
// Register
const response = await fetch('http://localhost:5000/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'newuser',
email: 'user@example.com',
password: 'SecurePass123'
})
});
const data = await response.json();
const token = data.access_token;
// Access protected endpoint
const protectedResponse = await fetch('http://localhost:5000/api/protected', {
headers: {
'Authorization': `Bearer ${token}`
}
});
import requests
# Register
response = requests.post('http://localhost:5000/auth/register', json={
'username': 'newuser',
'email': 'user@example.com',
'password': 'SecurePass123'
})
token = response.json()['access_token']
# Access protected endpoint
headers = {'Authorization': f'Bearer {token}'}
protected_response = requests.get('http://localhost:5000/api/protected', headers=headers)
ishield-server/
βββ app.py # Main Flask application
βββ config.py # Configuration settings
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ src/
β βββ auth.py # Authentication blueprint
β βββ api.py # API blueprint
β βββ models.py # Database models
β βββ vision/ # Your existing vision modules
βββ templates/ # HTML templates
β βββ index.html
β βββ login.html
β βββ register.html
β βββ dashboard.html
βββ static/ # Static files
βββ css/
β βββ style.css
βββ js/
βββ login.js
βββ register.js
βββ dashboard.js
β οΈ IMPORTANT: Before deploying to production:
SECRET_KEY and JWT_SECRET_KEY in config.py or use environment variablesDEBUG=False in productionMIT License
Feel free to submit issues and enhancement requests!
4 commits
Python
49.7%
HTML
25.4%
JavaScript
20.5%
CSS
2.7%
TypeScript
1.5%