Coder Social home page Coder Social logo

naderbhrr / fastify-example-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smartiniongithub/fastify-example

0.0 0.0 0.0 1.96 MB

Example webapp with Fastify

License: Apache License 2.0

CSS 16.49% JavaScript 75.64% HTML 1.26% Dockerfile 2.61% EJS 4.01%

fastify-example-1's Introduction

fastify-example

Docker Pulls Code Style dependencies Status devDependencies Status Known Vulnerabilities Apache 2.0 License

Example webapp with Fastify

Setup and run

To complete project setup, do:

npm install

and run with

npm start

then point your browser to localhost:8000

Setup and run with Docker

Note that it's possible to let Docker do all inside a container, because all is described in a Dockerfile; see Dockerfile-usage for related commands.

Of course you need a local installation of Docker (recent, if possible latest), but nothing other.

Setup and run with Docker images at DockerHub

A simpler way to run the webapp is by using published images at DockerHub: smartiniatdocker09/fastify-example. Default images are based on default Node.js Docker image and contains development dependencies too (to reload content, run tests, etc), BASH shell, etc; there are even others:

  • a variant one based on official Node.js Alpine Linux image, which is minimal (smaller, a lot) and is tailored for running in Production (dedicated user for running the webapp, no dev dependencies, no reload, etc)
  • another based on official Distroless images for Node.js (from Google), small (but bigger than those based on Alpine Linux) and without a lot of stuff inside (there is no shell for example), so not so simple to debug but good for production environments Note that "normal" images are not so small (approx. 900 / 1000 MB) and could contain some vulnerability in some packages already installed in the OS, so pay attention if/when using them in production environments.

For example, you can run directly with: docker run -d -p 8000:8000 -t smartiniatdocker09/fastify-example:latest-alpine and browse to localhost:8000. Published Docker tags are 'latest' / 'latest-alpine', and starting from source code tag '2.2.0' there is: the same tag, and even the '2.2.0-alpine' variant. For more info look at tags - smartiniatdocker09/fastify-example.

Of course you need a local installation of Docker (recent, if possible latest), but nothing other.

Others

To run a development server (with hot reload enabled) instead execute this:

npm run start:dev

For other custom commands look the 'scripts' section inside 'package.json'.

Requirements

Fastify ^2.15.3, Node.js 12 LTS (12.13.0) or later.

Sources

Source code is all inside main repo: fastify-example.

Documentation generated from source code (API): here.

Note

Some features can be configured via environment variables; if a .env file is found in project root, all its contents will be loaded into environmental variables. Supported variables:

  • FASTIFY_OPTIONS, set Fastify main options at startup, as a JSON string; to change logging level for example use something like: `{ "logger": { "level": "debug" } }' and to remove logging for example use: '{ }'
  • HTTP_PORT, set default HTTP port for the server
  • HTTP_ADDRESS, set default HTTP address for the server
  • NATS_SERVER_URL, set the URL for the NATS server (if enabled), or plugin default
  • WEBHOOK_SECRET_KEY, set the secret key to require by exposed webhook
  • FEATURE_PLATFORM_INFO_DISABLE, to disable the logging of some info related to the current runtime platform like: Node.js version, OS name, Fastify version, Webapp version, etc ...
  • FEATURE_CHECK_RUNTIME_ENV_DISABLE, to disable (not load) related plugin; if enabled and current Node.js environment is not compatible with the one set in 'package.json' by default it will throw an exception, so the webapp will crash (to avoid running the webapp in a not compliant env)
  • FEATURE_FAVICON_DISABLE, to disable (not load) related plugin
  • FEATURE_WEBHOOK_DISABLE, to disable (not load) related plugin
  • FEATURE_HEALTHCHECK_DISABLE, to disable (not load) related plugin
  • FEATURE_CLOUDEVENTS_DISABLE, to disable (not load) related plugin; note that this by default uses a public NATS server so disable it if not needed or if that server is not reachable for corporate firewall policies
  • FEATURE_CLOUDEVENTS_STRICT_DISABLE, to disable strict mode in generated CloudEvents (if/when related plugin is enabled)
  • FEATURE_CLOUDEVENTS_LOG_CONSOLE_DISABLE, to disable CloudEvent serialization to console
  • FEATURE_CLOUDEVENTS_LOG_FILE_DISABLE, to disable CloudEvent serialization to console, by default true (so disabled); note that when enabled a new log file will be created at any run of the server, but previous (if present) will be overwritten, so any new run is fresh and old logs will be discarded
  • FEATURE_NATS_DISABLE, to disable (not load) related plugin if not specified default behavior will be applied.

As a sample, by default (unless disabled) some messages will be sent to a NATS queue, when the web application has started and when a client ask for a page. NATS server by default (in related plugin) is a public one, demo.nats.io.

License

Licensed under Apache-2.0.


fastify-example-1's People

Contributors

smartiniongithub avatar plug-n-play avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.