Skip to content

Commit 2650a62

Browse files
committed
fix frontend
1 parent f037a29 commit 2650a62

30 files changed

+1287
-98
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ htmlcov/
1212
*.pem
1313
.idea/
1414
.vscode/
15+
node_modules
16+
npm-debug.log*

.env.development

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Schema Configuration
2+
SCHEMA_URL=http://localhost:80/schema/demo-protocol.json
3+
LOCAL_SCHEMA_DIR=./schemas
4+
5+
# Service Ports
6+
FRONTEND_PORT=3000
7+
BACKEND_PORT=8000
8+
PORT=80
9+
SSL_PORT=443
10+
11+
# Environment Settings
12+
NODE_ENV=development
13+
DEV_MODE=1
14+
PROJECT_NAME=development
15+
16+
# Nginx Settings
17+
NGINX_HOST=localhost

.env.example

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
data/
2+
schemas/
3+
responses/
4+
15
*.pyc
26
__pycache__
37
.env

Makefile

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
.PHONY: build up down test lint clean help
1+
.PHONY: build build-verbose up down test lint clean help run stop logs debug
22

33
help:
44
@echo "Available commands:"
55
@echo " make build - Build Docker images"
6+
@echo " make build-verbose - Build with detailed logs"
67
@echo " make up - Start the deployment"
78
@echo " make down - Stop the deployment"
89
@echo " make test - Run tests"
910
@echo " make lint - Run linters"
1011
@echo " make clean - Clean up Docker resources"
12+
@echo " make run - Run the container"
13+
@echo " make stop - Stop the container"
14+
@echo " make logs - View container logs"
15+
@echo " make debug - Show config and container state"
1116

1217
build:
1318
docker compose build
1419

20+
build-verbose:
21+
docker compose build --no-cache --progress=plain 2>&1 | tee build.log
22+
1523
up:
16-
docker compose up -d
24+
docker compose up --force-recreate --remove-orphans
1725

1826
down:
19-
docker compose down
27+
docker compose down --remove-orphans
2028

2129
test:
2230
docker compose -f docker-compose.dev.yml up -d
@@ -28,5 +36,26 @@ lint:
2836
docker compose -f docker-compose.dev.yml exec backend isort .
2937

3038
clean:
31-
docker compose down -v
39+
docker compose down -v --remove-orphans
3240
docker system prune -f
41+
docker rm -f reproschema-server
42+
43+
run:
44+
docker compose up -d
45+
46+
stop:
47+
docker compose down
48+
49+
logs:
50+
docker compose logs -f
51+
52+
debug:
53+
@echo "=== Config Files ==="
54+
@echo "\n=== Bundled JS Files ==="
55+
docker compose exec reproschema-server ls -la /usr/share/nginx/html/js/
56+
@echo "\n=== Config Values in Bundle ==="
57+
docker compose exec reproschema-server grep -A 10 "githubSrc" /usr/share/nginx/html/js/app.*.js
58+
@echo "\n=== Environment Variables ==="
59+
docker compose exec reproschema-server env | grep -E 'SCHEMA|TOKEN|PORT|BACKEND|ASSETS'
60+
@echo "\n=== Nginx Config ==="
61+
docker compose exec reproschema-server cat /etc/nginx/conf.d/default.conf | grep -A 5 "location.*${ASSETS_PUBLIC_PATH}"

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
1-
# reproschema-deployment
1+
# ReproSchema Deployment Container
2+
3+
A containerized solution for deploying ReproSchema UI with data collection capabilities. Simply provide your schema (either from GitHub or local files) and start collecting data.
4+
5+
## Quick Start
6+
7+
1. Create a `.env` file with your configuration:
8+
```bash
9+
# Required
10+
PROJECT_NAME=my_study # Name for your deployment
11+
SCHEMA_SOURCE=local # 'local' or 'github'
12+
13+
# For GitHub schemas
14+
GITHUB_REPO=user/repo # Only needed if SCHEMA_SOURCE=github
15+
GITHUB_TOKEN=ghp_xxx # Optional: for private repositories
16+
17+
# Optional
18+
PORT=3000 # Default: 3000
19+
```
20+
21+
2. Start the container:
22+
23+
For local schema:
24+
```bash
25+
# Place your schema files in ./schemas directory
26+
mkdir schemas
27+
cp -r my-schema/* schemas/
28+
29+
# Start the container
30+
docker compose up -d
31+
```
32+
33+
For GitHub schema:
34+
```bash
35+
# Start with GitHub repository
36+
SCHEMA_SOURCE=github GITHUB_REPO=user/repo docker compose up -d
37+
```
38+
39+
3. Access the UI at `http://localhost:3000`
40+
41+
## Data Storage
42+
43+
Participant data is automatically stored in a Docker volume named `${PROJECT_NAME}_data`. To backup or export the data:
44+
45+
```bash
46+
# Export data
47+
docker run --rm -v ${PROJECT_NAME}_data:/data -v $(pwd):/backup alpine tar czf /backup/data.tar.gz /data
48+
```
49+
50+
## Configuration Options
51+
52+
- `SCHEMA_SOURCE`: Source of the schema files
53+
- `local`: Use schema files from mounted volume
54+
- `github`: Fetch schema from GitHub repository
55+
- `GITHUB_REPO`: GitHub repository containing schema (format: user/repo)
56+
- `GITHUB_TOKEN`: GitHub personal access token for private repositories
57+
- `PORT`: Port to expose the service (default: 3000)
58+
- `PROJECT_NAME`: Name for the deployment (affects volume names)
59+
60+
## Directory Structure for Local Schema
61+
62+
When using `SCHEMA_SOURCE=local`, organize your schema files as follows:
63+
64+
```
65+
schemas/
66+
├── protocol.jsonld
67+
├── activities/
68+
│ ├── activity1.jsonld
69+
│ └── activity2.jsonld
70+
└── items/
71+
├── item1.jsonld
72+
└── item2.jsonld
73+
```
74+
75+
## Examples
76+
77+
Check the `examples/` directory for sample configurations:
78+
- `examples/simple-schema`: Basic single-protocol setup
79+
- `examples/multi-participant`: Setup for multiple participant data collection

config/nginx/default.conf

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,94 @@
1-
# Replace or edit config/nginx/default.conf with:
1+
map $http_x_forwarded_proto $forwarded_scheme {
2+
default $scheme;
3+
https https;
4+
}
5+
26
server {
37
listen 80;
8+
listen 443 ssl;
49
server_name localhost;
510

6-
root /usr/share/nginx/html;
7-
index index.html;
11+
# SSL and basic config
12+
ssl_certificate /etc/nginx/ssl/cert.pem;
13+
ssl_certificate_key /etc/nginx/ssl/key.pem;
14+
error_log /var/log/nginx/error.log debug;
15+
access_log /var/log/nginx/access.log;
16+
17+
# Security headers
18+
add_header X-Frame-Options "SAMEORIGIN" always;
19+
add_header X-XSS-Protection "1; mode=block" always;
20+
add_header X-Content-Type-Options "nosniff" always;
21+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
22+
add_header Content-Security-Policy "
23+
default-src 'self' https: http://0.0.0.0 http://localhost:*;
24+
script-src 'self' 'unsafe-inline' 'unsafe-eval';
25+
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
26+
img-src 'self' data: https:;
27+
font-src 'self' data: https://fonts.gstatic.com;
28+
connect-src 'self' https: http://0.0.0.0 http://localhost:* https://raw.githubusercontent.com https://github.com https://api.github.com;
29+
worker-src 'self' blob:;
30+
" always;
31+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
32+
33+
# CORS headers
34+
add_header 'Access-Control-Allow-Origin' '*' always;
35+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
36+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Accept' always;
37+
38+
# Root location for frontend
39+
location = / {
40+
return 302 $scheme://$http_host${ASSETS_PUBLIC_PATH};
41+
}
42+
43+
# Frontend files
44+
location "${ASSETS_PUBLIC_PATH}" {
45+
alias /usr/share/nginx/html/;
46+
index index.html;
47+
try_files $uri $uri/ "${ASSETS_PUBLIC_PATH}index.html";
48+
49+
# Static assets
50+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
51+
expires 30d;
52+
add_header Cache-Control "public, no-transform";
53+
try_files $uri =404;
54+
}
855

9-
# Handle local schemas
56+
# JSON-LD files
57+
location ~* \.(jsonld|json)$ {
58+
add_header Content-Type application/ld+json;
59+
add_header Cache-Control "no-cache";
60+
expires 0;
61+
}
62+
}
63+
64+
# Backend API
65+
location /api/ {
66+
proxy_pass http://localhost:8000/;
67+
proxy_set_header Host $host;
68+
proxy_set_header X-Real-IP $remote_addr;
69+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
70+
proxy_set_header X-Forwarded-Proto $forwarded_scheme;
71+
}
72+
73+
# GitHub raw content proxy
74+
location /raw/ {
75+
proxy_pass https://raw.githubusercontent.com;
76+
proxy_ssl_server_name on;
77+
proxy_set_header Host raw.githubusercontent.com;
78+
add_header 'Access-Control-Allow-Origin' '*' always;
79+
}
80+
81+
# Local schemas
1082
location /schemas/ {
11-
alias /usr/share/nginx/html/schemas/;
12-
try_files $uri $uri/ =404;
13-
14-
# Enable CORS
15-
add_header 'Access-Control-Allow-Origin' '*';
16-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
17-
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
83+
alias /schemas/;
84+
autoindex on;
85+
add_header 'Access-Control-Allow-Origin' '*' always;
1886
}
1987

20-
# Handle SPA routing
21-
location / {
22-
try_files $uri $uri/ /index.html;
88+
location /schema/ {
89+
proxy_pass https://raw.githubusercontent.com;
90+
proxy_ssl_server_name on;
91+
proxy_set_header Host raw.githubusercontent.com;
92+
add_header 'Access-Control-Allow-Origin' '*' always;
2393
}
24-
}
94+
}

config/nginx/prod.conf

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)