Skip to content

Commit

Permalink
Add fastify example (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob authored Jan 16, 2024
1 parent 91d0d28 commit 82d732d
Show file tree
Hide file tree
Showing 6 changed files with 547 additions and 0 deletions.
34 changes: 34 additions & 0 deletions starter/fastify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Dependencies
/node_modules
/.pnp
.pnp.js

# Testing
/coverage

# Production
build
dist

# Misc
.DS_Store
*.pem

# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Local ENV files
.env.local
.env.development.local
.env.test.local
.env.production.local

# Vercel
.vercel

# Turborepo
.turbo
21 changes: 21 additions & 0 deletions starter/fastify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Fastify + Vercel

This example shows how to use Fastify with Vercel Functions.

## Demo

https://fastify-example.vercel.app/

## Running Locallly

```bash
npm i
npm i -g vercel@latest
vercel dev
```

## One-Click Deploy

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):

[![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)
66 changes: 66 additions & 0 deletions starter/fastify/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Fastify from 'fastify'

const app = Fastify({
logger: true,
})

app.get('/', async (req, reply) => {
return reply.status(200).type('text/html').send(html)
})

export default async function handler(req, reply) {
await app.ready()
app.server.emit('request', req, reply)
}

const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@exampledev/[email protected]/new.min.css"
/>
<title>Vercel + Fastify Hello World</title>
<meta
name="description"
content="This is a starter template for Vercel + Fastify."
/>
</head>
<body>
<h1>Vercel + Fastify Hello World</h1>
<p>
This is a starter template for Vercel + Fastify. Requests are
rewritten from <code>/*</code> to <code>/api/*</code>, which runs
as a Vercel Function.
</p>
<p>
For example, here is the boilerplate code for this route:
</p>
<pre>
<code>import Fastify from 'fastify'
const app = Fastify({
logger: true,
})
app.get('/', async (req, res) => {
return res.status(200).type('text/html').send(html)
})
export default async function handler(req: any, res: any) {
await app.ready()
app.server.emit('request', req, res)
}</code>
</pre>
<p>
<p>
<a href="https://vercel.com/templates/other/fastify-serverless-function">
Deploy your own
</a>
to get started.
</body>
</html>
`
9 changes: 9 additions & 0 deletions starter/fastify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "fastify",
"repository": "https://github.com/vercel/examples.git",
"license": "MIT",
"private": true,
"dependencies": {
"fastify": "^4.25.2"
}
}
Loading

71 comments on commit 82d732d

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kv-redis-starter – ./storage/kv-redis-starter

nextjs-kv-starter.vercel.app
kv-starter.vercel.app
kv-redis-starter-git-main.vercel.rocks
kv-redis-starter.vercel.rocks
kv-redis-starter.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

examples – ./storage/postgres-starter

examples-bice.vercel.app
examples.vercel.rocks
examples-git-main.vercel.rocks

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

postgres-drizzle – ./storage/postgres-drizzle

postgres-drizzle.vercel.app
postgres-drizzle.vercel.rocks
postgres-drizzle-git-main.vercel.rocks

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blob-starter – ./storage/blob-starter

blob-starter.vercel.app
blob-starter-git-main.vercel.rocks
blob-starter.vercel.rocks

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-flask – ./python/nextjs-flask

nextjs-python.vercel.app
next-flask.vercel.rocks
next-flask-git-main.vercel.rocks
nextjs-flask-starter.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-functions-news – ./starter/next-news

edge-functions-news-git-main-now-examples.vercel.app
edge-functions-news-now-examples.vercel.app
edge-functions-next-news.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solutions-image-offset – ./solutions/image-offset

solutions-image-offset-git-main-now-examples.vercel.app
solutions-image-offset.vercel.app
solutions-image-offset-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-rewrites-upstash – ./edge-middleware/rewrites-upstash

edge-rewrites-upstash-now-examples.vercel.app
edge-rewrites-upstash-git-main-now-examples.vercel.app
edge-rewrites-upstash.vercel.app
edge-rewrites-upstash.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solutions-on-demand-isr – ./solutions/on-demand-isr

solutions-on-demand-isr.vercel.app
solutions-on-demand-isr-now-examples.vercel.app
solutions-on-demand-isr-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-user-agent-based-rendering – ./edge-middleware/user-agent-based-rendering

edge-user-agent-based-rendering-now-examples.vercel.app
edge-user-agent-based-rendering.vercel.app
edge-user-agent-based-rendering-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solutions-loading-web-fonts – ./solutions/loading-web-fonts

solutions-loading-web-fonts-now-examples.vercel.app
solutions-loading-web-fonts.vercel.app
solutions-loading-web-fonts-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feature-flag-optimizely – ./edge-middleware/feature-flag-optimizely

feature-flag-optimizely.vercel.app
feature-flag-optimizely-git-main-now-examples.vercel.app
feature-flag-optimizely-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-maintenance-page – ./edge-middleware/maintenance-page

edge-maintenance-page.vercel.app
edge-maintenance-page-now-examples.vercel.app
edge-maintenance-page-git-main-now-examples.vercel.app
edge-maintenance-page.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solutions-script-component-ad – ./solutions/script-component-ad

solutions-script-component-ad-git-main-now-examples.vercel.app
solutions-script-component-ad-now-examples.vercel.app
solutions-script-component-ad.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-ab-testing-statsig – ./edge-middleware/ab-testing-statsig

edge-ab-testing-statsig-now-examples.vercel.app
edge-ab-testing-statsig.vercel.app
edge-ab-testing-statsig-git-main-now-examples.vercel.app
edge-ab-testing-statsig.vercel.sh

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

i18n – ./edge-middleware/i18n

i18n-git-main-now-examples.vercel.app
i18n-now-examples.vercel.app
i18n.vercel.sh
middleware-i18n.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app-dir-i18n – ./app-directory/i18n

app-dir-i18n-now-examples.vercel.app
app-dir-i18n.vercel.app
app-dir-i18n-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app-dir-css-in-js – ./app-directory/css-in-js

app-dir-css-in-js-now-examples.vercel.app
app-dir-css-in-js.vercel.app
app-dir-css-in-js-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app-dir-share-state – ./app-directory/share-state

app-dir-share-state-now-examples.vercel.app
app-dir-share-state.vercel.app
app-dir-share-state-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-middleware-modify-request-header – ./edge-middleware/modify-request-header

edge-middleware-modify-request-header-now-examples.vercel.app
edge-middleware-modify-request-header.vercel.app
edge-middleware-modify-request-header-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-geolocation-country-block – ./edge-middleware/geolocation-country-block

edge-geolocation-country-block.vercel.app
edge-geolocation-country-block-now-examples.vercel.app
edge-geolocation-country-block-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feature-flag-launchdarkly – ./edge-middleware/feature-flag-launchdarkly

feature-flag-launchdarkly-git-main-now-examples.vercel.app
feature-flag-launchdarkly-now-examples.vercel.app
feature-flag-launchdarkly.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nodejs-api – ./solutions/node-hello-world

nodejs-api-now-examples.vercel.app
nodejs-api-example.vercel.app
nodejs-api-murex.vercel.app
nodejs-api-git-main-now-examples.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 82d732d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feature-flag-hypertune – ./edge-middleware/feature-flag-hypertune

feature-flag-hypertune.vercel.app
feature-flag-hypertune-git-main-now-examples.vercel.app
feature-flag-hypertune-now-examples.vercel.app

Please sign in to comment.