-
Notifications
You must be signed in to change notification settings - Fork 1k
/
deno.html.markerb
163 lines (117 loc) · 5.54 KB
/
deno.html.markerb
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: "Run a Deno App"
layout: language-and-framework-docs
sitemap: false
redirect_from:
- /docs/languages-and-frameworks/deno/
- /docs/getting-started/deno/
order: 2
---
<%= partial "partials/intro", locals: { runtime: "[Deno](https://deno.land)" } %>
## _The Hellodeno Application_
Our example will be a basic "hello world" example using Deno and [Dinatra](https://github.com/syumai/dinatra).
You can get the code for the example from [the hellodeno GitHub repository](https://github.com/fly-apps/hellodeno). Just `git clone https://github.com/fly-apps/hellodeno` to get a local copy. Here's all the code:
```typescript
import {
app,
get,
post,
redirect,
contentType,
} from "https://denopkg.com/syumai/dinatra/mod.ts";
const greeting = "<h1>Hello From Deno on Fly!</h1>";
app(
get("/", () => greeting),
get("/:id", ({ params }) => greeting + `</br>and hello to ${params.id}`),
);
```
We'll call this file `main.ts`. We also want a `deps.ts` file for dependencies, here it is:
```typescript
export {
app,
get,
post,
redirect,
contentType,
} from "https://denopkg.com/syumai/dinatra/mod.ts";
```
There's nothing else to run. Deno will manage getting packages for itself.
## Running The Application
Run `deno run --allow-net main.ts` to start the application:
```cmd
deno run --allow-net main.ts
```
```output
listening on http://0.0.0.0:8080/
```
And connect to localhost:8080 to confirm that you have a working Deno application by receiving a greeting. Now to package it up for Fly.io. There are a number of ways to do this. You can use flyctl's own simple builder,
## Install Flyctl and Login
We are ready to start working with Fly.io, and that means we need `flyctl`, our CLI app for managing apps on Fly.io. If you've already installed it, carry on. If not, hop over to [our installation guide](/docs/hands-on/install-flyctl/). Once that's installed you'll want to [log in to Fly.io](/docs/getting-started/log-in-to-fly/).
## Configuring the App for Fly.io
Each Fly App needs a `fly.toml` file to tell the system how we'd like to deploy it.
That file can be automatically generated with the command `flyctl launch` command. This command will also generate a Dockerfile for deployment.
```cmd
fly launch
```
```output
Creating app in /fly/guides/hellodeno
Scanning source code
Detected Deno app
? Select organization: myorg (myorg)
? Select region: ams (Amsterdam, Netherlands)
Created app empty-sea-2541 in organization myorg
Wrote config file fly.toml
Your app is ready. Deploy with `flyctl deploy`
? Would you like to deploy now? (y/N)
```
First you'll be prompted for an organization. Organizations are a way of sharing applications between Fly.io users. When you are asked to select an organization, there should be one with your account name; this is your personal organization. Select that.
Then, pick the region you want to deploy in.
## Inside `fly.toml`
The `fly.toml` file now contains a default configuration for deploying your app. In the process of creating that file, `flyctl` has also created a Fly-side application slot of the same name, "hellodeno". If we look at the `fly.toml` configuration file we can see the name in there:
```toml
app = "empty-sea-2541"
[processes]
app = "run --allow-net ./example.ts"
...
```
We can also see a default `run` command for the main web process. We can change that to refer to `./main.ts`.
The `flyctl` command will always refer to this file in the current directory if it exists, specifically for the `app` name/value at the start. That name will be used to identify the application to the Fly.io platform.
The rest of the file contains settings to be applied to the application when it deploys.
## Deploying to Fly.io
We are now ready to deploy our containerized app to Fly.io. At the command line, just run:
```cmd
fly deploy
```
This will lookup our `fly.toml` file and get the app name `empty-sea-2541` from there.
Then `flyctl` will start the process of deploying our application to Fly.io using the Dockerfile. Flyctl will return you to the command line when it's done.
## Viewing the Deployed App
If you want to find out more about the deployment. The command `fly status` will give you all the essential details.
```cmd
fly status
```
```output
App
Name = empty-sea-2541
Owner = dj
Version = 0
Status = running
Hostname = empty-sea-2541.fly.dev
Allocations
ID VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
73f825ad 0 fra run running 1 total, 1 passing 0 6m34s ago
```
## _Connecting to the App_
The quickest way to view your application is to run `fly apps open` which will open your browser on the URL for your application. Run `fly apps open /name` to get an extra greeting from the app.
If you want to manually enter a URL to check, remember to replace `empty-sea-2541.fly.dev` with the hostname you got from `fly status` and connect to `http://hellodeno.fly.dev/` where you should find a greeting - it will normally be upgraded to a secure connection. Use `https://hellodeno.fly.dev` to start with a secure connection. Add `/name` and you'll get an extra greeting from the hellodeno application.
## Bonus Points
If you want to know what IP addresses the app is using, try `fly ips list`:
```cmd
fly ips list
```
```out
TYPE ADDRESS REGION CREATED AT
v4 213.188.199.2 global 2021-04-22T23:23:01Z
v6 2a09:8280:1:2958:3b6c:fdfd:70f9:da9d 2021-04-22T23:23:01Z
```
## Arrived at Destination
You have successfully built, deployed, and connected to your first Deno application on Fly.io.