Skip to content

This project is a small but feature complete application build with Fastify and Svelte, and it aims to show all the core concepts of Fastify, best practices, and recommendations.

License

Notifications You must be signed in to change notification settings

Ulisseruiz/fastify-example

 
 

Repository files navigation

Fastify App Example

This project is a small but feature complete application build with Fastify and Svelte, and it aims to show all the core concepts of Fastify, best practices, and recommendations.

There is no attached blog post or tutorial, you should go through the application code and read the code comments, which will explain you best practices, protips, suggestions and so forth, I hope you will like it!

Project structure

How should I read through the comments?

You you can read the project in any order, but I would recommend the following:

  1. plugins/authorization/index.js
  2. plugins/elasticsearch.js
  3. plugins/rate-limit.js
  4. plugins/validUrl.js
  5. plugins/swagger.js
  6. routes/status.js
  7. routes/frontend.js
  8. routes/admin.js
  9. routes/redirect/index.js
  10. routes/redirect/update-count.js
  11. routes/redirect/worker.cjs
  12. routes/redirect/App.svelte
  13. ui/*
  14. test/helper.js
  15. test/plugins/validUrl.test.js
  16. test/routes/status.test.js
  17. test/routes/admin.test.js.test.js
  18. test/routes/redirect.test.js.test.js

How to run this project

  1. Create an .env file from the template:

    cp .env.template .env
  2. Create a new GitHub OAuth application here, then copy the app id and secret and add them to the env file:

    GITHUB_APP_ID=<app-id>
    GITHUB_APP_SECRET=<app-secret>
  3. Add your primary GitHub email to the ALLOWED_USERS variable:

    ALLOWED_USERS=<your-primary-github-mail>
  4. Run the keys-generator script and store the result in the COOKIE_SECRET env variable:

    node scripts/keys-generator.js
    COOKIE_SECRET=<generated-key>

Now you can either run the project locally or deploy it.

Locally

  1. Install the project dependencies:

    npm install
  2. In a separate terminal window, run Elasticsearch:

    npm run elasticsearch
  3. Once Elasticsearch is up and running, run the prepare-elasticsearch script and copy the result in the ELASTIC_URL and ELASTIC_API_KEY env variables:

    node scripts/prepare-elasticsearch.js
    ELASTIC_URL=<result.address>
    ELASTIC_API_KEY=<result.apiKey>
  4. You are all set! Run the project with thw following command:

    npm run dev

Deploy

This sections contains the instruction for deploying this application.

Would you like to see more recipes? Open an issue. Do you already have a deploy recipe and want to share it? That's awesome, send a pull request!

Cloud Run

Open deploy-recipes/cloud-run, you will find everything you need there.

Elastic Cloud

You can create an Elasticsearch cluster with Elastic Cloud, with a free 14-day trial of the Elasticsearch Service.

Contribute

Feel free to send pull request with new features, bugfix or documentation improvements!

Questions

Open an issue or take a look at our fastify/help repository. We also have a Discord community you can join.

If you have any question related to Elasticsearch or the Elasticsearch client, you can open a new discussion on discuss.elastic.co or in the client issue tracker.

License

This software is licensed under the Apache 2 license.

About

This project is a small but feature complete application build with Fastify and Svelte, and it aims to show all the core concepts of Fastify, best practices, and recommendations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 79.2%
  • Svelte 18.0%
  • HTML 1.9%
  • Other 0.9%