1628584657
fastify-cors enables the use of CORS in a Fastify application.
Supports Fastify versions 3.x. Please refer to this branch and related versions for Fastify ^2.x compatibility. Please refer to this branch and related versions for Fastify ^1.x compatibility.
npm i fastify-cors
Require fastify-cors and register it as any other plugin, it will add a preHandler hook and a wildcard options route.
const fastify = require('fastify')()
fastify.register(require('fastify-cors'), {
// put your options here
})
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
})
fastify.listen(3000)
You can use it as is without passing any option or you can configure it as explained below.
const fastify = require('fastify')()
fastify.register(require('fastify-cors'), (instance) => (req, callback) => {
let corsOptions;
// do not include CORS headers for requests from localhost
if (/localhost/.test(origin)) {
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
}
callback(null, corsOptions) // callback expects two parameters: error and options
})
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
})
fastify.listen(3000)
The code is a port for Fastify of expressjs/cors.
Licensed under MIT.
expressjs/cors license
origin: (origin, cb) => {
if(/localhost/.test(origin)){
// Request from localhost will pass
cb(null, true)
return
}
// Generate an error on other origins, disabling access
cb(new Error("Not allowed"))
}
1628175900
Fastify uses find-my-way to handle routing. This option may be set to true to ignore trailing slashes in routes. This option applies to all route registrations for the resulting server instance.
Default: false
const fastify = require('fastify')({
ignoreTrailingSlash: true
})
// registers both "/foo" and "/foo/"
fastify.get('/foo/', function (req, reply) {
reply.send('foo')
})
// registers both "/bar" and "/bar/"
fastify.get('/bar', function (req, reply) {
reply.send('bar')
})
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ ignoreTrailingSlash: true })
);
}
1626996180
Fastify is a web framework for Node.js that has a great satisfaction across developers with a 89% rating in the last state of javascript. Fastify combines an amazing developer experience with top of the class performance, with minimal reduction on top of Node.js core. In this talk, we will go through the fundamentals of the framework as well as a live coded example.
#fastify #node.js #javascript
1626564480
Fastify a node.js framework, it is a quick look into fastify, what is it how do you use it and some basic validation rules. We will make a mistake and see how the framework response to it. We will dive into some nice features that are different than express.js. It has a lot of plugins, so it is also easy to extend and use the power of the ecosystem.
In my opinion a nice framework that you need to take into account when you are searching for a node.js framework to build big enterprise ready api’s with. The validation hooks are a great and awesome feature of it.
It gets a typewithme approved seal!
#fastify #node.js
1626166378
If you’re wanting all the greatness of Next.js without having to deploy on the Vercel platform then look no further, use a custom server with Fastify! 3 main reasons why this is worth it:
Use the backend systems you know - ie Fastify - no having to learn how serverless works or how Next.js handles it’s backend API requests in a specific way
Keep full access to realtime features - server side events, websockets, socket.io, etc!
Don’t get tied to a separate platform when you really want to use Next.js for your next project. Using a Fastify custom server you can containerize your app and be on your way!
Github Repo with working example:
https://github.com/wolfejw86/blog-exa…
Subscribe: https://www.youtube.com/c/JayWolfe/featured
#react #typescript #fastify
1626110760
In this video we’ll build and deploy a Fastify web server to AWS, fine tuning the settings to optimize performance and achieve single digit millisecond latency.
Fine tune your Lambda settings with Lambda Power Tuning - https://github.com/alexcasalboni/aws-lambda-power-tuning
Blog post - https://dev.to/aws/deep-dive-finding-the-optimal-resources-allocation-for-your-lambda-functions-35a6
0:00 - Introduction
0:57 - Getting started - creating the project
2:45 - Writing the server
5:45 - Configuring Lambda settings
6:56 - Deploying the backend
7:08 - Testing it out & viewing logs
9:09 - Conclusion
#aws amplify #aws #fastify
1625987731
In this video we take a look at a crash course of Fastify as another web / API framework for NodeJS. We discuss how it is similar or differs from something like ExpressJS. We create a new application from scratch using typescript and the fastify CLI. We also take a look at how JSON Schema factors into the application and how to make that work well with TypeScript.
#fastify #express #typescript #node
1625641713
Use Notion to create a database, connect to the Notion API, and create a small Node.js server.
Discover Notion, a project management software similar to Trello and Airtable, and use its API to build the backend of a database.
Notion is a customizable project management software that makes it easy to collaborate on projects and pages, share your work internally or externally, and keep track of teammates.
Notion is easy to use and is a favorite of both tech and non-tech companies. Some popular alternatives to Notion are Trello, Jira, and Airtable.
Notion recently released the Notion API, which allows developers to build on top of Notion. While still in public beta, we can use the Notion API to develop and test our own application.
In this tutorial, we’ll use Notion to create a database, connect to the Notion API, and create a small Node.js server that uses Fastify to serve up content from our Notion workspace. Note that this tutorial will only build out the backend of the application.
To follow along with this tutorial, you’ll need to have a basic knowledge of JavaScript and Node.js.
Let’s get started!
#notion #api #node #nodejs #fastify
1625108233
Want to see what all the buzz is about with Test Driven Development(TDD)? Look no further! In this video we’ll walk through the TDD thought process using a Fastify healthcheck API along with Jest tests as an example. The process is simple:
1. Think about what your new feature needs to do in the code.
2. Write a test that “expects” your app to do that.
3. Run the test in “watch mode”.
4. Write code until your test passes!
Github Repo with working example:
https://github.com/wolfejw86/blog-exa…
Subscribe: https://www.youtube.com/c/JayWolfe/featured
#jest #fastify
1624175083
Fastify is a web framework for Node.js that has a great satisfaction across developers with a 89% rating in the last state of javascript. Fastify combines an amazing developer experience with top of the class performance, with minimal reduction on top of Node.js core. In this talk, we will go through the fundamentals of the framework as well as a live coded example.
#fastify #nodejs #node #web-development
1624029813
Fastify is a “fast” Node.js framework. In this video, we will build a REST API with validation schemas and swagger documentation
Code:
https://github.com/bradtraversy/fastify-crash-course
Website & Docs:
https://www.fastify.io/
Timestamps:
#node #fastify #web-development
1620092827
Custom Cache plugin in Fastify using hooks and node-cache.
Timestamps:
#fastify
1620057181
In this video I look at Fastify and see why it’s better or not better the Express.js. Then I create a quick CRUD app out of it, and show you how easy it is to work!.
#express #fastify #node
1619501703
Building software that works is one thing, building software that last is another, especially when the code size increases rapidly together with the number of people involved in its development.
In this article we will go through some maintainability issues and techniques to avoid them, using a nodejs web server built with Fastify (web framework) and Mongodb (database) as example.
This particular service is a simple CRUD store for movies, but for many web services, you can scatter in the same way their various components somewhere along a line:
The bits on the left are very common and have probably little added value for your specific application. The relative value of your service lies in the data you have/collect and what you do with this data (the business logic).
It is important to note that the borders between the layers are not strict and may vary for different projects.
For example, a team with high skills in RDMS can do data aggregation and statistical calculation within a SQL query/function while another team will chose to do the same in the application code, finding it easier to maintain and test.
However, separating the different concerns will ease the maintainability of the codebase anyway, that is what we are going to review here.
#javascript #fastify #clean-code #nodejs
1619486854
Plugins 101. Fastify web framework for Node.js. REST API Routes, .env, MongoDB.
➥ Repo: https://github.com/pragmatic-reviews/fastify-test/tree/fastify-plugins
Timestamps:
#fastify #node #mongodb