File size: 3,830 Bytes
9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f 9eca774 570e75f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | FROM directus/directus:11.15.4
USER root
# Install curl untuk health check
RUN apk add --no-cache curl
# ============================================
# GATEWAY SETUP (FOLDER TERPISAH - PENTING!)
# ============================================
RUN mkdir -p /gateway
WORKDIR /gateway
# Buat package.json dengan CommonJS mode
RUN echo '{"name":"gateway","type":"commonjs"}' > package.json
# Install http-proxy DI SINI, bukan di /directus!
RUN npm install http-proxy
# Buat gateway script
RUN cat > /gateway/server.js << 'GWEOF'
const http = require("http");
const httpProxy = require("http-proxy");
const DOMAIN = process.env.DOMAIN || "";
const proxy = httpProxy.createProxyServer({
target: "http://127.0.0.1:8055",
ws: true,
changeOrigin: true
});
proxy.on("error", (err, req, res) => {
console.error("[Gateway Error]", err.message);
if (res && res.writeHead) {
res.writeHead(502, { "Content-Type": "text/plain" });
res.end("502 - Directus sedang loading...");
}
});
function isAllowed(req) {
if (!DOMAIN) return true;
const h = [
req.headers["x-real-domain"] || "",
req.headers["x-forwarded-host"] || "",
req.headers["host"] || ""
].join("|");
return h.includes(DOMAIN);
}
const server = http.createServer((req, res) => {
if (req.url === "/ping" || req.url === "/health") {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("OK");
return;
}
if (isAllowed(req)) {
proxy.web(req, res);
} else {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("OK");
}
});
server.on("upgrade", (req, socket, head) => {
if (isAllowed(req)) {
proxy.ws(req, socket, head);
} else {
socket.destroy();
}
});
server.listen(7860, "0.0.0.0", () => {
console.log("[Gateway] Listening on :7860");
console.log("[Gateway] Proxying to Directus :8055");
if (DOMAIN) console.log("[Gateway] Domain filter:", DOMAIN);
});
GWEOF
# ============================================
# BRANDING FILES
# ============================================
WORKDIR /directus
RUN mkdir -p /directus/uploads
COPY ./branding/ /directus/uploads/
# ============================================
# STARTUP SCRIPT
# ============================================
RUN cat > /start.sh << 'STARTEOF'
#!/bin/sh
set -e
echo "============================================"
echo " Starting Directus (Whitelabel Edition)"
echo "============================================"
cd /directus
# Step 1: Bootstrap (migrations + create admin)
echo "[1/3] Running bootstrap..."
node cli.js bootstrap 2>&1 || echo "[1/3] Bootstrap done (or skipped)"
# Step 2: Start Directus
echo "[2/3] Starting Directus on port 8055..."
node cli.js start &
# Wait for Directus to be ready
echo "[2/3] Waiting for Directus..."
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
sleep 4
if curl -sf http://127.0.0.1:8055/server/ping > /dev/null 2>&1; then
echo "[2/3] ✅ Directus is ready!"
break
fi
echo "[2/3] Still waiting... ($i/15)"
done
# Step 3: Start Gateway
echo "[3/3] Starting Gateway on port 7860..."
cd /gateway
exec node server.js
STARTEOF
RUN chmod +x /start.sh
# ============================================
# FIX PERMISSIONS
# ============================================
RUN chown -R node:node /gateway /start.sh /directus/uploads
# ============================================
# ENVIRONMENT DEFAULTS
# ============================================
ENV HOST="0.0.0.0"
ENV PORT="8055"
ENV LOG_LEVEL="info"
ENV TELEMETRY="false"
ENV CACHE_ENABLED="true"
ENV RATE_LIMITER_ENABLED="false"
# Whitelabel defaults (bisa override via HF Secrets)
ENV PROJECT_NAME="My Custom CMS"
ENV PROJECT_COLOR="#6644ff"
EXPOSE 7860
USER node
CMD ["/start.sh"] |