summaryrefslogtreecommitdiff
path: root/packages/integrations/deno/readme.md
blob: 4b3dc959fa8d8551ebc551c6ce06805522b582ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# @astrojs/deno

A server-side rendering adapter for use with Deno targets. Write your code in Astro/Node and deploy to Deno servers.

In your astro.config.mjs use:

```js
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  adapter: deno()
});
```

After performing a build there will be a `dist/server/entry.mjs` module. You can start a server simply by importing this module:

```js
import './dist/entry.mjs';
```

## API

### Adapter options

This adapter automatically starts a server when it is imported. You can configure this through options:

```js
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  adapter: deno({
    start: false
  })
});
```

If disabling start you need to write your own web server and use `handle` to render requests:

```ts
import { serve } from "https://deno.land/std@0.132.0/http/server.ts";
import { handle } from './dist/entry.mjs';

serve((req: Request) => {
  // Check the request, maybe do static file handling here.

  return handle(req);
});
```

----

You an also pass in a port/hostname to use:

```js
import { defineConfig } from 'astro/config';
import deno from '@astrojs/deno';

export default defineConfig({
  adapter: deno({
    port: 8081,
    hostname: 'myhost'
  })
});
```