Skip to content

Commit 82d732d

Browse files
authored
1 parent 91d0d28 commit 82d732d

File tree

6 files changed

+547
-0
lines changed

6 files changed

+547
-0
lines changed

starter/fastify/.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# Dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# Testing
9+
/coverage
10+
11+
# Production
12+
build
13+
dist
14+
15+
# Misc
16+
.DS_Store
17+
*.pem
18+
19+
# Debug
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
24+
# Local ENV files
25+
.env.local
26+
.env.development.local
27+
.env.test.local
28+
.env.production.local
29+
30+
# Vercel
31+
.vercel
32+
33+
# Turborepo
34+
.turbo

starter/fastify/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Fastify + Vercel
2+
3+
This example shows how to use Fastify with Vercel Functions.
4+
5+
## Demo
6+
7+
https://fastify-example.vercel.app/
8+
9+
## Running Locallly
10+
11+
```bash
12+
npm i
13+
npm i -g vercel@latest
14+
vercel dev
15+
```
16+
17+
## One-Click Deploy
18+
19+
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):
20+
21+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/starter/fastify&project-name=fastify&repository-name=fastify)

starter/fastify/api/index.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Fastify from 'fastify'
2+
3+
const app = Fastify({
4+
logger: true,
5+
})
6+
7+
app.get('/', async (req, reply) => {
8+
return reply.status(200).type('text/html').send(html)
9+
})
10+
11+
export default async function handler(req, reply) {
12+
await app.ready()
13+
app.server.emit('request', req, reply)
14+
}
15+
16+
const html = `
17+
<!DOCTYPE html>
18+
<html lang="en">
19+
<head>
20+
<meta charset="UTF-8" />
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
22+
<link
23+
rel="stylesheet"
24+
href="https://cdn.jsdelivr.net/npm/@exampledev/[email protected]/new.min.css"
25+
/>
26+
<title>Vercel + Fastify Hello World</title>
27+
<meta
28+
name="description"
29+
content="This is a starter template for Vercel + Fastify."
30+
/>
31+
</head>
32+
<body>
33+
<h1>Vercel + Fastify Hello World</h1>
34+
<p>
35+
This is a starter template for Vercel + Fastify. Requests are
36+
rewritten from <code>/*</code> to <code>/api/*</code>, which runs
37+
as a Vercel Function.
38+
</p>
39+
<p>
40+
For example, here is the boilerplate code for this route:
41+
</p>
42+
<pre>
43+
<code>import Fastify from 'fastify'
44+
45+
const app = Fastify({
46+
logger: true,
47+
})
48+
49+
app.get('/', async (req, res) => {
50+
return res.status(200).type('text/html').send(html)
51+
})
52+
53+
export default async function handler(req: any, res: any) {
54+
await app.ready()
55+
app.server.emit('request', req, res)
56+
}</code>
57+
</pre>
58+
<p>
59+
<p>
60+
<a href="https://vercel.com/templates/other/fastify-serverless-function">
61+
Deploy your own
62+
</a>
63+
to get started.
64+
</body>
65+
</html>
66+
`

starter/fastify/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "fastify",
3+
"repository": "https://github.com/vercel/examples.git",
4+
"license": "MIT",
5+
"private": true,
6+
"dependencies": {
7+
"fastify": "^4.25.2"
8+
}
9+
}

0 commit comments

Comments
 (0)