File
Blob: samples/tcp/config.capnp
| 1 | # This example defines the configuration for a simple Gopher |
| 2 | # (https://en.wikipedia.org/wiki/Gopher_(protocol)) client, with an optional HTTP proxy |
| 3 | # configuration as well. |
| 4 | # |
| 5 | # The comments in this file focus on TCP-related configuration. For details about the rest check |
| 6 | # out the helloworld/config.capnp file (also under the samples directory). |
| 7 | # Also be sure to refer to the comments in /src/workerd/server/workerd.capnp. |
| 8 | |
| 9 | using Workerd = import "/workerd/workerd.capnp"; |
| 10 | |
| 11 | const helloWorldExample :Workerd.Config = ( |
| 12 | |
| 13 | # Every workerd instance consists of a set of named services. A worker, for instance, |
| 14 | # is a type of service. Here we create a single worker service and an ExternalServer which |
| 15 | # defines a local proxy. The configuration details for these are defined below. |
| 16 | services = [ |
| 17 | (name = "main", worker = .gopherWorker), |
| 18 | (name = "proxy", external = .localProxy) |
| 19 | ], |
| 20 | |
| 21 | sockets = [ ( name = "http", address = "*:8080", http = (), service = "main" ) ] |
| 22 | ); |
| 23 | |
| 24 | # The definition of the actual worker exposed using the "main" service. |
| 25 | const gopherWorker :Workerd.Worker = ( |
| 26 | modules = [ |
| 27 | (name = "worker", esModule = embed "gopher.js") |
| 28 | ], |
| 29 | compatibilityDate = "2023-02-28", |
| 30 | # In order to access our configured proxy we need to specify it as a binding. This will allow |
| 31 | # it to be accessible via `env.proxy` in the JS script. |
| 32 | bindings = [ |
| 33 | (name = "proxy", service = "proxy") |
| 34 | ] |
| 35 | ); |
| 36 | |
| 37 | # The definition of an external server which in this case is an HTTP proxy. Any connections made |
| 38 | # through it will be tunneled using HTTP CONNECT. |
| 39 | const localProxy :Workerd.ExternalServer = ( |
| 40 | address = "localhost:1234", |
| 41 | http = ( |
| 42 | style = proxy |
| 43 | ) |
| 44 | ); |