Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Example environment variables for Interstellar

# Port to listen on (defaults to 8080 in code)
PORT=8080

# If enabled, MASQR integration is active (see README and Masqr.js)
# Set to "true" to enable license validation and Masqr features
MASQR=false

# Use this env flag to enable password protection per README instructions
# The project uses `config.js` as the primary config; you can set this env if you prefer
# (some deployment setups use it). If your runtime respects this, set to "true".
CONFIG=false

# Example: set to run behind a specific host/IP if needed
HOST=0.0.0.0

# Node environment
NODE_ENV=development
Empty file.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ RUN npm install

COPY . .

# Expose port and add a lightweight healthcheck
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1

CMD [ "node", "index.js" ]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ As of January 1st, 2024, Replit is [no longer free](https://blog.replit.com/host
5. Access the deployed website from the ports tab.
6. For subsequent uses in the same codespace, just run `pnpm start`

### Health checks

This repository exposes a simple health endpoint at `/healthz` which returns a JSON object with `status`, `uptime`, and the package `version`. The endpoint is used by the included Dockerfile `HEALTHCHECK` and by Kubernetes liveness/readiness probes.

Docker `HEALTHCHECK` example (included in this repo):

```
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1
```

Use `/healthz` in monitoring, load balancers, and container orchestrators to verify the service is healthy.

### Solution for if there is no popup.

1. Run `pnpm i`, and before `pnpm start`, prepend `PORT=8080`, replacing 8080 with another port. For example, `PORT=6969 pnpm start`.
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ const routes = [
{ path: "/", file: "index.html" },
];

// Health-check endpoint
app.get("/healthz", (_req, res) => {
try {
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
res.json({ status: "ok", uptime: process.uptime(), version: pkg.version });
} catch (err) {
res.status(500).json({ status: "error", error: err.message });
}
});
// biome-ignore lint: idk
routes.forEach(route => {
app.get(route.path, (_req, res) => {
Expand Down Expand Up @@ -138,4 +147,5 @@ server.on("listening", () => {
console.log(chalk.green(`🌍 Server is running on http://localhost:${PORT}`));
});

server.listen({ port: PORT });
// Bind to all interfaces so the app is reachable from the container/host
server.listen({ port: PORT, host: "0.0.0.0" });
Empty file added k8s/deployment.yaml
Empty file.