Files
shopdb-flask/wsgi.py
cproudlock 6010f01de1
Some checks failed
CI / backend (push) Successful in 1m41s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 8s
CI / migrations-mysql (push) Failing after 8s
Support subpath IIS deployment as a second install method
The app can run as an IIS Application under an existing site
(e.g. https://host/ops/) instead of its own site + port:

- frontend: vite base via VITE_BASE_PATH; router history, axios
  baseURL, and root-absolute asset/route paths resolve through
  utils/basePath.js withBase()
- backend: MOUNT_PATH (env or .env) wraps the app in a WSGI
  middleware that shifts the prefix into SCRIPT_NAME, so one knob
  serves API + SPA under the mount
- docs: INSTALL-WINDOWS-IIS.md section 7b runbook + troubleshooting
  rows; DEPLOY-WINDOWS-IIS.md pointer; commented examples in
  deploy/windows/web.config and .env.example

Root deployment unchanged (MOUNT_PATH unset, base '/'). Also folds
two stray root-absolute callers into the shared plumbing
(MachineForm relationship-types fetch, reports CSV window.open).
2026-07-13 16:11:12 -04:00

46 lines
1.7 KiB
Python

"""WSGI entry point for the application."""
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
from shopdb import create_app
app = create_app(os.environ.get('FLASK_ENV', 'development'))
class MountPathMiddleware:
"""Serve the whole app (API + SPA) under a URL prefix, e.g. '/ops'.
Used when the app is deployed as an IIS Application under an existing
site instead of its own site: IIS forwards the full request path
('/ops/api/...'), so the prefix is moved from PATH_INFO to SCRIPT_NAME
before Flask routes it. Flask then also generates URLs under the prefix.
The frontend must be built with the matching VITE_BASE_PATH ('/ops/').
"""
def __init__(self, wsgi_app, mountpath):
self.wsgi_app = wsgi_app
self.mountpath = '/' + mountpath.strip('/')
def __call__(self, environ, start_response):
path = environ.get('PATH_INFO', '')
if path == self.mountpath or path.startswith(self.mountpath + '/'):
environ['SCRIPT_NAME'] = environ.get('SCRIPT_NAME', '') + self.mountpath
environ['PATH_INFO'] = path[len(self.mountpath):] or '/'
return self.wsgi_app(environ, start_response)
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return [b'Not Found: the app is mounted at ' + self.mountpath.encode() + b'/']
# MOUNT_PATH (.env or web.config) activates the subpath deployment method.
# Unset/empty = the app owns the server root (its own IIS site; the default).
_mountpath = os.environ.get('MOUNT_PATH', '').strip()
if _mountpath and _mountpath != '/':
app.wsgi_app = MountPathMiddleware(app.wsgi_app, _mountpath)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True)