This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
56 lines (45 loc) · 1.4 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const path = require('path')
const AutoLoad = require('@fastify/autoload')
module.exports.options = {}
module.exports = async function (fastify, opts) {
// Module to serve static resources
const fastifyStatic = require('@fastify/static')
// Public resources served under /public
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'public'),
prefix: '/public/',
})
// Access to /node_modules through /lib
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'node_modules'),
prefix: '/lib/',
decorateReply: false
})
// Registering the EJS engine for the view
fastify.register(require("@fastify/view"), {
engine: {
ejs: require("ejs"),
},
});
// We need this to work with the SW in the "/public" scope
fastify.addHook('preHandler', (req, reply, done) => {
reply.header('Service-Worker-Allowed', '/')
//reply.header('Cache-Control', 'max-age=300, must-revalidate')
done()
})
// i18n capabilities. 'en' by default
fastify.register(require('fastify-polyglot'), {
defaultLocale: 'en',
localesPath: path.join(__dirname, './i18n')
})
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign({}, opts)
})
// Register the routes defined in '/routes'
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts)
})
}