Deploy Deno Apps
Deno installation is powered by webi. To install latest version with deployment script:
features:
- deno
Without this, deno won't be available since no globally installed Deno runtime available.
Install other version using deno latest, deno 1.13, etc. To uninstall use deno off. Check the current version using deno --version from SSH.
Example
The deployment script below installs the latest deno compiler, writes app.ts and run deno run --allow-net app.ts serving HTTP from PORT envar..
source: clear
features:
- deno latest
nginx:
root: public_html/public
passenger:
enabled: "on"
app_start_command: deno run --allow-net app.ts --port=$PORT
commands:
- filename: app.ts
content: |
import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts";
const flags = parse(Deno.args, {
string: ["port"],
default: { port: "8080" },
});
const html_text = `
<!DOCTYPE html>
<html>
<head>
<title>Deno App</title>
<link rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css">
</head>
<body class="p-5 text-center">
<p><img src="//images.unsplash.com/photo-1465153690352-10c1b29577f8?fit=crop&w=200&h=200"
class="img-fluid rounded-circle"></p>
<h1 class="mb-3">Hello, world!</h1>
<p>Serving from Deno version ${Deno.version.deno}</p>
<p class="text-muted">DOM Cloud</p>
</body>
</html>
`
const server = Deno.listen({ port: parseInt(flags.port) });
for await (const conn of server) {
serveHttp(conn);
}
async function serveHttp(conn: Deno.Conn) {
const httpConn = Deno.serveHttp(conn);
for await (const requestEvent of httpConn) {
requestEvent.respondWith(
new Response(html_text, {
headers: {
"content-type": "text/html",
},
status: 200,
}),
);
}
}
For existing deno apps, use this deployment script. Please adjust relevant fields such as the startup file (change app.ts), allowed features (change --allow-net) and how $PORT is delivered (either deno ... --port=$PORT or env PORT=$PORT deno ...).
features:
- deno latest
nginx:
root: public_html/public
passenger:
enabled: "on"
app_start_command: deno run --allow-net app.ts --port=$PORT
App Management
Your app do not restarted automatically after file changes. To restart, run restart via SSH.
Environment variables can be set either using NGINX's env_var_list or ~/.bashrc. Usually your language framework also reads .env files.
See NGINX and App Daemon for more information about NGINX and App managements including restarting, environment variables, and other global limitations.
App Logging
You can see app log from Check -> Check Process Logs tab. Only startup problems displayed in the browser.
You might want to use a proper logging mechanism such as the standard logging library then write it to a log file, or any other solution that suits you.
NGINX errors and traffic logs can be examined via Webmin or Check -> Check Process Logs tab.