cchub-web
Official Web Server & HTTP Tunnel Gateway client for ComputerCraft in JavaScript (hJS) and Lua.
Host live public websites, dashboards, and REST APIs straight from your in-game ComputerCraft computers and turtles! Anyone on the real internet can access your computer at: https://cc.jeremyleonklink.de/web/<your-site-name>
🚀 Quickstart in JavaScript (hJS)
1. Install via hpm
bash
hpm install cchub-web2. Create main.hjs
javascript
const { createServer } = require("cchub-web");
const app = createServer({
site: "my-base",
token: "YOUR_SECRET_TOKEN" // from https://cc.jeremyleonklink.de/web
});
// HTML Webpage
app.get("/", (req, res) => {
res.html(`
<!DOCTYPE html>
<html>
<head><title>My Base</title></head>
<body style="font-family: sans-serif; background: #111; color: #eee; padding: 2rem;">
<h1>⚡ Live Minecraft Base Server</h1>
<p>Served directly by ComputerCraft & hJS!</p>
<p>In-game time: ${os.time()}</p>
</body>
</html>
`);
});
// JSON API
app.get("/api/status", (req, res) => {
res.json({
status: "online",
time: os.time(),
day: os.day(),
fuel: typeof turtle !== "undefined" ? turtle.getFuelLevel() : null
});
});
// Serve static files from /www folder
app.static("/www");
app.listen((url) => {
console.log("Server live at: " + url);
});3. Run It!
bash
hjs run main.hjs📜 Quickstart in Lua
If you prefer standard Lua:
lua
local web = require("cchub-web")
local app = web.createServer({
site = "my-base",
token = "YOUR_SECRET_TOKEN"
})
app.get("/", function(req, res)
res.html("<h1>Hello from Minecraft ComputerCraft!</h1>")
end)
app.get("/api/status", function(req, res)
res.json({ status = "online", time = os.time() })
end)
app.listen()📚 API Reference
createServer(options)
site(string, required): The slug registered under/web.token(string, required): Secret access token generated for this tunnel.endpoint(string, optional): Default ishttps://cc.jeremyleonklink.de.
Routing Methods
app.get(path, handler)app.post(path, handler)app.put(path, handler)app.delete(path, handler)app.all(path, handler)app.static(folderPath, mountPoint = "/")app.listen([callback])app.close()
Request Object (req)
req.method: HTTP method ("GET","POST", etc.)req.path: Requested path (e.g."/api/status")req.query: Object of query string parametersreq.headers: Object containing HTTP headersreq.body: Raw request body string
Response Object (res)
res.status(statusCode): Sets HTTP status code (200, 404, 500, etc.)res.header(name, value): Sets a response headerres.html(htmlString): Sends HTML withContent-Type: text/htmlres.json(data): Sends JSON withContent-Type: application/jsonres.text(textString): Sends plain textres.send(data): Sends raw response body