Merge pull request 'Add new env variable to use prefixes in url [release-patch]' (#8) from dev into main

Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
2025-11-25 09:57:16 +00:00
3 changed files with 36 additions and 1 deletions

View File

@@ -75,6 +75,18 @@ jobs:
run: |
git config user.name "Gitea CI"
git config user.email "ci@git.theprivateserver.de"
- name: Determine branch to push to
id: push_branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# workflow_dispatch runs on a branch ref like refs/heads/main
BRANCH=${GITHUB_REF#refs/heads/}
else
# for a merged PR use the PR base ref (target branch)
BRANCH=${{ github.event.pull_request.base.ref }}
fi
echo "PUSH_BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Bump version
id: bump
run: |
@@ -133,7 +145,7 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
branch: ${{ env.PUSH_BRANCH }}
- name: Build Changelog
id: build_changelog
uses: https://github.com/mikepenz/release-changelog-builder-action@v5

View File

@@ -38,6 +38,7 @@ jobs:
with:
name: semapform-image
path: semapform-api.tar
retention-days: 1
smoke-tests:
needs: build-image

View File

@@ -12,6 +12,28 @@ from fastapi.responses import JSONResponse
app = FastAPI(title="Signature Validation API")
# Optional path prefix support: when behind a reverse-proxy that uses a
# URL prefix (eg. `https://api.example.tld/library/...`) set `API_PREFIX` to
# that prefix (example: `/library`) so incoming requests are rewritten to the
# application root. This keeps route definitions unchanged while supporting
# both proxied and direct deployments.
_api_prefix_raw = os.getenv("API_PREFIX", "").strip()
api_prefix = ""
if _api_prefix_raw:
if not _api_prefix_raw.startswith("/"):
_api_prefix_raw = "/" + _api_prefix_raw
api_prefix = _api_prefix_raw.rstrip("/")
@app.middleware("http")
async def _strip_api_prefix(request, call_next):
if api_prefix and request.url.path.startswith(api_prefix):
new_path = request.url.path[len(api_prefix) :]
request.scope["path"] = new_path or "/"
request.scope["root_path"] = api_prefix
return await call_next(request)
# Allow PHP application to call this API
app.add_middleware(
CORSMiddleware,