Running TypeScript
Catch has specific support for running TypeScript files with Deno. Deno allows you to specify dependencies directly within the file. Under the hood, Catch runs your TypeScript file inside the denoland/deno Docker container.
Running TypeScript files is as simple as using yeet run
or yeet cron
. Catch will automatically detect the file type
and run it using Deno.
yeet run my_service index.ts
Examples
Deploying a simple HTTP server
In this example, we'll deploy a simple HTTP server written in TypeScript. Our server will listen on port 8080
and
respond to GET requests at the root path with a "Hello, World!" message.
// index.ts
import { serve } from "https://deno.land/[email protected]/http/server.ts";
const server = serve({ port: 8080 });
for await (const req of server) {
req.respond({ body: "Hello, World!" });
}
Similar to shell scripts, there's no building required. The next step is to run the script using yeet run
. Catch will
automatically detect that the file is a TypeScript file and run it using Deno.
yeet run hello-deno index.ts
We can check that the service is running with yeet status
.
$ yeet status my_service
SERVICE TYPE CONTAINER STATUS
hello-deno service - running
Our server is running on port 8080
. Let's curl
our server to see that it's running.
$ curl http://<ip-of-server>:8080
Hello, World!
Catch includes a built-in TCP proxy, enabling you to access your services over the Tailnet. This means you can simply curl http://catch:8080
to reach your service.