Skip to content

Commit

Permalink
chore(docs): add runtime apis docs (#201)
Browse files Browse the repository at this point in the history
* chore(docs): add runtime apis docs

* feat: add --env option to cli doc

* feat: complete runtime APIs
  • Loading branch information
QuiiBz authored Nov 2, 2022
1 parent 0d2cd1a commit b3d250f
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/docs/pages/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We recommend to install the CLI globally, using the package manager of your choi
# NPM
npm install --global @lagon/cli
# Yarn
npm global add @lagon/cli
yarn global add @lagon/cli
# PNPM
pnpm install --global @lagon/cli
```
Expand Down Expand Up @@ -69,7 +69,7 @@ lagon deploy ./server.tsx --client App.tsx --public ./assets
### `lagon undeploy`

<Callout type="error">
Un-deploying a Function deletes permanently all of its Deployments, statistics and logs. You will prompted to confirm before continuing.
Un-deploying a Function deletes permanently all of its Deployments, statistics and logs. You will be prompted to confirm before continuing.
</Callout>

Un-deploy completely a Function. Make sure you are [logged in](#lagon-login) before proceeding. This command accept only one argument:
Expand All @@ -86,10 +86,11 @@ lagon undeploy ./index.ts

Launch a local dev server, using the same Runtime as when deployed to the Cloud.

This command accept the same arguments and options as `lagon deploy` and `lagon build`. It can also accept two more options to configure the server hostname and port:
This command accept the same arguments and options as `lagon deploy` and `lagon build`. It can also accept the following options:

- `--hostname <HOSTNAME>` allows you to specify a custom hostname the start the server on. (Default: `127.0.0.1`)
- `--port <PORT>` allows you to specify a custom port the start the server on. (Default: `1234`)
- `--env <PATH>` allows you to specify an environment file (typically `.env`) to use to inject environment variables.

<Callout type="warning">
Although the `dev` command uses the exact same Runtime as when deployed, the local HTTP server itself doesn't have the same optimizations. As such, you shouldn't run a production environment on it, or run any kind of load tests/benchmarks.
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/pages/cloud/organizations.mdx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Organizations
Work in progress...
119 changes: 118 additions & 1 deletion packages/docs/pages/runtime-apis.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,118 @@
Work in progress...
import { Callout } from 'nextra-theme-docs'

The following APIs are the same as the Web APIS you already know. Additionally, we follow the [WinterCG](https://wintercg.org/) conventions.

## Handler

The only required code to make your Function runnable is to export a `handler` function, that accepts a [`Request`](#request) and returns a [`Response`](#response) (or a promise returning a Response):

```typescript
export function handler(request: Request): Response {
return new Response('Hello World!')
}
```

Starting from this simple code, you can do whatever you whish, using the Web APIs you already know.

## Global objects

### `console`

Similar to the the standard `console` object on the browser and on Node.js, expect that it only supports the following methods:

- `log`
- `info`
- `debug`
- `warn`
- `error`

You can log multiple objects, and use string substitution. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#outputting_text_to_the_console).

### `process`

The only usage of `process` is to get [environment variables](/cloud/environment-variables) via `process.env`.

Example:

```typescript
export function handler(request: Request): Response {
return new Response(`My secret is: ${process.env.SECRET}`)
}
```

### `TextEncoder`

The standard `TextEncoder` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder).

### `TextDecoder`

The standard `TextDecoder` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder).

### Fetch

<Callout type="info">
Looking for the `fetch()` method? [Jump to fetch()](#fetch-1).
</Callout>

#### `Request`

The standard `Request` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request).

#### `Response`

The standard `Response` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Response).

**Streaming**:
You can pass a [`ReadableStream`](#readablestream) object as the `body` of a `Response` to stream the response as more data becomes available. Often, you won't need to implement the logic yourself as it is implemented by the frameworks and libraries you use.

#### `URL`

The standard `URL` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/URL).

<Callout type="warning">
This URL implementation only supports URLs with a scheme.
</Callout>

#### `URLSearchParams`

The standard `URLSearchParams` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).

#### `Headers`

The standard `Headers` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Headers).

### Streams

#### `ReadableStream`

The standard `ReadableStream` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).

#### `ReadableStreamDefaultReader`

The standard `ReadableStreamDefaultReader` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader).

#### `WritableStream`

The standard `WritableStream` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).

#### `WritableStreamDefaultWriter`

The standard `WritableStreamDefaultWriter` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter).

#### `TransformStream`

The standard `TransformStream` object. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream).

## Global methods

### `fetch()`

The standard `fetch` method. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/fetch).

### `atob()`

The standard `atob` method. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/atob).

### `btoa()`

The standard `btoa` method. [See the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/API/btoa).

0 comments on commit b3d250f

Please sign in to comment.