add fastify starter (#107)

This commit is contained in:
Faraz Patankar
2021-05-26 09:33:41 +04:00
committed by GitHub
parent 1d6dfe352f
commit 8ff32051c4
6 changed files with 1283 additions and 0 deletions

2
examples/fastify/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/node_modules
/dist

View File

@@ -0,0 +1,28 @@
---
title: Fastify
description: A Fastify server
tags:
- fastify
- typescript
---
# Fastify Example
This example starts a [Fastify](https://www.fastify.io/) server.
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https%3A%2F%2Fgithub.com%2Frailwayapp%2Fexamples%2Ftree%2Fmaster%2Fexamples%2Ffastify)
## ✨ Features
- Fastify
- TypeScript
## 💁‍♀️ How to use
- Install dependencies `yarn`
- Connect to your Railway project `railway link`
- Start the development server `railway run yarn dev`
## 📝 Notes
The server started simply returns a `{ message: "Hello world!" }` payload in JSON. The server code is located in the `index.ts` file.

15
examples/fastify/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import fastify from "fastify";
const server = fastify();
server.get("/", async (request, reply) => {
reply.code(200).send({ message: "Hello world!" });
});
server.listen(8080, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server listening at ${address}`);
});

View File

@@ -0,0 +1,21 @@
{
"name": "fastify",
"version": "1.0.0",
"main": "index.js",
"author": "Faraz Patankar",
"license": "MIT",
"scripts": {
"dev": "nodemon index.ts",
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js"
},
"dependencies": {
"fastify": "^3.15.1"
},
"devDependencies": {
"@types/node": "^15.6.1",
"nodemon": "^2.0.7",
"ts-node": "^10.0.0",
"typescript": "^4.2.4"
}
}

View File

@@ -0,0 +1,13 @@
{
"compilerOptions": {
"outDir": "dist",
"incremental": true,
"target": "es6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}

1204
examples/fastify/yarn.lock Normal file

File diff suppressed because it is too large Load Diff