Template for building REST APIs and web applications running on Fastify. The idea behind this project is to minimize an effort on creating web application backend through unified server core and rather concentrate on writing URL/route handlers.
So that's what it does. all you need to do is to write your route handlers.
Clone sources locally
git clone https://github.com/skitsanos/fastify-server-template.git
Install dependencies
cd fastify-server-template
npm install
Minimal folder structure for your Fastify driven application would look like this:
--/
/config
/framework
/routes
Although if you are running full blown application with HTML rendering via Handlebars
--/
/config
/framework
/routes
/schemas
/ui
Although this template allows you to run your server as it is, there is number of things you can configure by modifying /config/server.json file.
"static": {
"root": "ui"
},
Setting static.root property to 'ui' will enable serving static content from {server root}/ui folder.
"cookies": {}
If configuration has cookies section, server will enable fastify-cookie plugin. This plugin's cookie parsing works via Fastify's onRequest hook. More details about this plugin you can read here: https://github.com/fastify/fastify-cookie
For the moment only handlebars is supported.
"viewEngine": {
"engine": "handlebars",
"templatesDir": "ui",
"partialsDir": "ui/partials",
"config": {
"preventIndent": true
}
},
The HTTP Upgrade-Insecure-Requests request header sends a signal to the server expressing the client's preference for an encrypted and authenticated response, and that it can successfully handle the upgrade-insecure-requests CSP directive.
"upgradeInsecureRequests": false,
If enabled, once request received with upgrade-insecure-requests HTTP header, server will redirect request to HTTPS version.
CORS default configuration (/config/cors.js)
{
"origin": "*",
"allowedHeaders": [
"Content-Type",
"Authorization"
]
}