ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(buildpack): serve vite builds with a host-agnostic static server
Juan Denisebb53d8fcc5e
diff --git a/backend/app/services/buildpack_service.py b/backend/app/services/buildpack_service.pyindex 0847e660..b4d106b3 100644--- a/backend/app/services/buildpack_service.py+++ b/backend/app/services/buildpack_service.py@@ -170,7 +170,13 @@ class BuildpackService:plan['start_command'] = scripts.get('start') or 'node .output/server/index.mjs'elif 'vite' in deps:framework, port = 'vite', 4173- plan['start_command'] = scripts.get('start') or 'vite preview --host --port 4173'+ # NOT `vite preview`: preview host-checks the request against+ # `preview.allowedHosts` and blocks any domain the repo's vite+ # config doesn't list -- dead on arrival behind the panel's+ # proxy. `serve -s` does SPA fallback, no host check; the+ # generator preinstalls it when the start command needs it.+ plan['start_command'] = (scripts.get('start')+ or 'serve -s dist -l tcp://0.0.0.0:4173')elif 'express' in deps or 'fastify' in deps or 'koa' in deps:framework, port = ('express' if 'express' in deps else 'node'), 3000plan['start_command'] = scripts.get('start') or 'node index.js'@@ -538,6 +544,10 @@ class BuildpackService:lines.append('COPY . .')if build:lines.append(f'RUN {build}')+ if start.split(' ', 1)[0] == 'serve':+ # The buildpack chose `serve` itself (vite default) -- the repo+ # won't declare it, so preinstall it globally.+ lines.append('RUN npm install -g serve')lines += ['ENV NODE_ENV=production',f'EXPOSE {port}',diff --git a/backend/tests/test_buildpacks.py b/backend/tests/test_buildpacks.pyindex 5fcec585..ec0ed253 100644--- a/backend/tests/test_buildpacks.py+++ b/backend/tests/test_buildpacks.py@@ -175,6 +175,40 @@ def test_generate_dockerfile_node_build_keeps_dev_dependencies():assert df.index('RUN npm install\n') < df.index('RUN npm run build')+def test_detect_vite_defaults_to_serve_not_preview(tmp_path):+ """`vite preview` host-checks against preview.allowedHosts and blocks+ every domain the panel proxy forwards -- the default start command must+ be a host-agnostic static server, and the generator must preinstall it+ (the repo never declares serve)."""+ (tmp_path / 'package.json').write_text(json.dumps({+ 'name': 'v', 'scripts': {'build': 'vite build'},+ 'devDependencies': {'vite': '^6.0.0'},+ }), encoding='utf-8')++ plan = BuildpackService.detect(str(tmp_path))+ assert plan['framework'] == 'vite'+ assert plan['start_command'].startswith('serve ')+ assert 'preview' not in plan['start_command']++ df = BuildpackService.generate_dockerfile(plan)+ assert 'RUN npm install -g serve' in df+++def test_detect_vite_repo_start_script_wins(tmp_path):+ """A repo-authored start script is the author's contract -- keep it,+ and don't preinstall serve for a command that doesn't use it."""+ (tmp_path / 'package.json').write_text(json.dumps({+ 'name': 'v', 'scripts': {'build': 'vite build',+ 'start': 'node server.mjs'},+ 'devDependencies': {'vite': '^6.0.0'},+ }), encoding='utf-8')++ plan = BuildpackService.detect(str(tmp_path))+ assert plan['start_command'] == 'node server.mjs'+ assert 'RUN npm install -g serve' not in \+ BuildpackService.generate_dockerfile(plan)++def test_generate_dockerfile_node_without_build_omits_dev():plan = {'builder': 'nixpacks', 'language': 'node', 'framework': 'express',diff --git a/backend/tests/test_real_buildpack_docker.py b/backend/tests/test_real_buildpack_docker.pyindex a6a36009..ce7765f2 100644--- a/backend/tests/test_real_buildpack_docker.py+++ b/backend/tests/test_real_buildpack_docker.py@@ -106,6 +106,24 @@ def _deploy_and_probe(repo_path, expect_language, expect_framework=None,breakexcept (OSError, AssertionError):time.sleep(1)+ if body is not None:+ # Behind the panel's proxy the request carries the app's+ # DOMAIN as Host, not 127.0.0.1 -- a server that host-checks+ # (vite preview's preview.allowedHosts) answers localhost+ # probes fine and blocks every real visitor. Every generated+ # container must serve regardless of Host.+ req = urllib.request.Request(+ url, headers={'Host': 'app.example.com'})+ with urllib.request.urlopen(req, timeout=5) as resp:+ assert resp.status == 200, (+ 'container refused a foreign Host header -- it would '+ 'block every request forwarded by the panel proxy'+ )+ foreign_body = resp.read().decode('utf-8', 'replace')+ assert 'not allowed' not in foreign_body.lower(), (+ 'container host-blocked the proxied domain: '+ + foreign_body[:300]+ )if body is None:logs = subprocess.run(['docker', 'logs', tag],@@ -124,10 +142,11 @@ def _deploy_and_probe(repo_path, expect_language, expect_framework=None,capture_output=True, timeout=60)-def test_node_vite_build_and_preview(tmp_path):- """The gods-eye-view regression: vite is a devDependency, the build- command needs it at build time and the preview start command needs it- (via node_modules/.bin on PATH) at run time."""+def test_node_vite_build_and_serve(tmp_path):+ """The gods-eye-view regressions: vite is a devDependency the build+ needs at build time, and the container must answer requests for the+ app's real domain -- `vite preview` host-blocked everything the panel+ proxy forwarded (the helper's foreign-Host probe pins that)."""_write(tmp_path, {'package.json': json.dumps({'name': 'vite-smoke', 'version': '0.1.0', 'private': True,@@ -146,6 +165,7 @@ def test_node_vite_build_and_preview(tmp_path):})plan, body = _deploy_and_probe(tmp_path, 'node', 'vite')assert plan['build_command'] == 'npm run build'+ assert plan['start_command'].startswith('serve ')assert 'vite-smoke' in body