fix: serve the website dist so Coolify answers GET /
All checks were successful
CI — Website / Website — typecheck, build (pull_request) Successful in 1m1s
All checks were successful
CI — Website / Website — typecheck, build (pull_request) Successful in 1m1s
Nixpacks built Vite but had no production start command, so Coolify returned Cannot GET /. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
3
packages/website/.dockerignore
Normal file
3
packages/website/.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
*.md
|
||||
12
packages/website/Dockerfile
Normal file
12
packages/website/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:1.27-alpine
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
@@ -24,27 +24,45 @@ npm run website:build
|
||||
# → packages/website/dist/
|
||||
```
|
||||
|
||||
Preview production build: `npm run website:preview`.
|
||||
Preview production build locally: `npm run website:preview` (Vite, localhost only).
|
||||
|
||||
Uses HashRouter so the site works on static hosts without server-side rewrite rules.
|
||||
Production start (what Coolify should run): `npm start` — serves `dist/` on `0.0.0.0:$PORT` (default 3000).
|
||||
|
||||
Uses HashRouter so deep links work even without SPA rewrite rules. The production server still maps unknown paths to `index.html`.
|
||||
|
||||
## Deploy on Coolify
|
||||
|
||||
This package is a **static** Vite build (`dist/`). No LexAI API keys or env vars.
|
||||
This package is a static Vite build. No LexAI API keys or env vars. Do not add `LEXAI_API_KEY`.
|
||||
|
||||
1. In Coolify: **+ New** → **Resource** → **Private Repository (with deploy key)** (Gitea).
|
||||
2. Repo SSH URL, for example `git@git.juankibin.space:kibin/LexAI.git`. If Gitea SSH is not on port 22, use `ssh://git@git.juankibin.space:PORT/kibin/LexAI.git` (Coolify sometimes needs `ssh:///` with three slashes).
|
||||
`Cannot GET /` means Coolify started a Node process that is not serving `dist/` (no `start` command, or "static site" pointed at the wrong folder). Fix: use one of the two setups below, then **Redeploy**.
|
||||
|
||||
**Required on either setup**
|
||||
|
||||
1. **+ New** → **Resource** → **Private Repository (with deploy key)** (Gitea).
|
||||
2. Repo SSH URL, for example `git@git.juankibin.space:kibin/LexAI.git`. If Gitea SSH is not on port 22, use `ssh://git@git.juankibin.space:PORT/kibin/LexAI.git`.
|
||||
3. Add Coolify’s public deploy key to the Gitea repo: **Settings → Deploy / Access Keys** (read-only).
|
||||
4. Branch: `dev` or `main`.
|
||||
5. **Build Pack:** Nixpacks.
|
||||
6. **Base Directory:** `/packages/website` — required. Root `npm run build` builds Chrome, not this site.
|
||||
7. Enable **Is it a static site?**
|
||||
8. **Publish Directory:** `/dist`
|
||||
9. **Install command** (if the build says `vite: not found`): `npm ci` (do not omit devDependencies — Vite lives there).
|
||||
10. Optional env: `NIXPACKS_NODE_VERSION=22`
|
||||
11. Optional **Watch Paths:** `packages/website` so Chrome/VS Code/CLI commits do not redeploy.
|
||||
12. Set the domain, **Deploy**, then open `https://your-domain/#/docs`.
|
||||
5. **Base Directory:** `packages/website` — no leading slash. Root `npm run build` builds Chrome, not this site.
|
||||
6. Optional **Watch Paths:** `packages/website`.
|
||||
7. Set the domain, deploy, open `https://your-domain/` (docs: `https://your-domain/#/docs`).
|
||||
|
||||
### Option A — Dockerfile (recommended)
|
||||
|
||||
1. **Build Pack:** Dockerfile.
|
||||
2. Leave **Is it a static site?** **off**.
|
||||
3. **Ports Exposes:** `80`.
|
||||
4. If Coolify asks for a Dockerfile path: `packages/website/Dockerfile` (or omit it when Base Directory is already `packages/website`).
|
||||
|
||||
### Option B — Nixpacks
|
||||
|
||||
1. **Build Pack:** Nixpacks.
|
||||
2. Leave **Is it a static site?** **off**. Nixpacks runs `npm run build` then `node server.mjs`.
|
||||
3. **Start command** (if the field is shown): `npm start` or `node server.mjs`.
|
||||
4. **Ports Exposes:** `3000`.
|
||||
5. Optional env: `NIXPACKS_NODE_VERSION=22`. Do not set `NODE_ENV=production` at **build** time — Vite is a devDependency and `npm ci` would skip it.
|
||||
|
||||
Do **not** tick "Is it a static site?" with Publish Directory `/dist`. The leading slash is an absolute path (`/dist` on the container), which is empty, and Coolify then answers `Cannot GET /`.
|
||||
|
||||
If you already created the resource: uncheck static site, set Base Directory and port as above, then Redeploy (no need to recreate the app).
|
||||
|
||||
Auto-deploy: Coolify resource → **Webhooks** → copy the URL + secret into Gitea **Settings → Webhooks** (push events).
|
||||
|
||||
Do not add `LEXAI_API_KEY` or any provider key to this Coolify app.
|
||||
|
||||
16
packages/website/nginx.conf
Normal file
16
packages/website/nginx.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location = /healthz {
|
||||
access_log off;
|
||||
add_header Content-Type text/plain;
|
||||
return 200 'ok';
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,6 @@ cmds = ["npm ci"]
|
||||
|
||||
[phases.build]
|
||||
cmds = ["npm run build"]
|
||||
|
||||
[start]
|
||||
cmd = "node server.mjs"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"dev": "vite",
|
||||
"build": "tsc --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"start": "node server.mjs",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
81
packages/website/server.mjs
Normal file
81
packages/website/server.mjs
Normal file
@@ -0,0 +1,81 @@
|
||||
import { createReadStream, existsSync, statSync } from 'node:fs';
|
||||
import { createServer } from 'node:http';
|
||||
import { extname, join, resolve, sep } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = resolve(fileURLToPath(new URL('./dist', import.meta.url)));
|
||||
const port = Number(process.env.PORT) || 3000;
|
||||
const host = process.env.HOST || '0.0.0.0';
|
||||
|
||||
const MIME = {
|
||||
'.css': 'text/css; charset=utf-8',
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
'.ico': 'image/x-icon',
|
||||
'.js': 'text/javascript; charset=utf-8',
|
||||
'.json': 'application/json; charset=utf-8',
|
||||
'.map': 'application/json; charset=utf-8',
|
||||
'.png': 'image/png',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.txt': 'text/plain; charset=utf-8',
|
||||
'.webp': 'image/webp',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
};
|
||||
|
||||
function fileUnderRoot(urlPath) {
|
||||
const decoded = decodeURIComponent((urlPath ?? '/').split('?')[0] || '/');
|
||||
const relative = decoded.replace(/^\/+/, '').replaceAll('/', sep);
|
||||
const resolved = resolve(root, relative);
|
||||
const prefix = root.endsWith(sep) ? root : root + sep;
|
||||
if (resolved !== root && !resolved.startsWith(prefix)) return null;
|
||||
return resolved;
|
||||
}
|
||||
|
||||
function send(res, status, body, type = 'text/plain; charset=utf-8') {
|
||||
res.writeHead(status, { 'Content-Type': type, 'Cache-Control': 'no-cache' });
|
||||
res.end(body);
|
||||
}
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
if (req.method === 'GET' && (req.url === '/healthz' || req.url?.startsWith('/healthz?'))) {
|
||||
send(res, 200, 'ok');
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
send(res, 405, 'Method not allowed');
|
||||
return;
|
||||
}
|
||||
|
||||
const candidate = fileUnderRoot(req.url ?? '/');
|
||||
if (!candidate) {
|
||||
send(res, 400, 'Bad request');
|
||||
return;
|
||||
}
|
||||
|
||||
let file = candidate;
|
||||
if (!existsSync(file) || statSync(file).isDirectory()) {
|
||||
file = join(root, 'index.html');
|
||||
}
|
||||
if (!existsSync(file)) {
|
||||
send(res, 500, 'dist/ missing — run npm run build before start');
|
||||
return;
|
||||
}
|
||||
|
||||
const type = MIME[extname(file).toLowerCase()] ?? 'application/octet-stream';
|
||||
res.writeHead(200, { 'Content-Type': type });
|
||||
if (req.method === 'HEAD') {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
createReadStream(file).pipe(res);
|
||||
});
|
||||
|
||||
if (!existsSync(join(root, 'index.html'))) {
|
||||
console.error('dist/index.html missing — run npm run build before start');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
server.listen(port, host, () => {
|
||||
console.log(`LexAI website listening on http://${host}:${port}`);
|
||||
});
|
||||
@@ -3,5 +3,4 @@ import react from '@vitejs/plugin-react';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
base: './',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user