@opengis/fastify-table 2.0.8 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fp from 'fastify-plugin';
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -37,7 +38,7 @@ import authRoutes from "./server/routes/auth/index.js";
|
|
|
37
38
|
// core templates && cls
|
|
38
39
|
const filename = fileURLToPath(import.meta.url);
|
|
39
40
|
const cwd = path.dirname(filename);
|
|
40
|
-
|
|
41
|
+
function plugin(fastify) {
|
|
41
42
|
const opt = { prefix: '/api' };
|
|
42
43
|
// fastify.register(import('@fastify/sensible'), {
|
|
43
44
|
// errorHandler: false,
|
|
@@ -79,15 +80,15 @@ async function plugin(fastify) {
|
|
|
79
80
|
addTemplateDir(path.join(cwd, "module/core"));
|
|
80
81
|
// plugins / utils / funcs
|
|
81
82
|
policyPlugin(fastify);
|
|
82
|
-
|
|
83
|
+
authPlugin(fastify); // fastify-auth api + hooks integrated to core
|
|
83
84
|
metricPlugin();
|
|
84
85
|
redisPlugin(fastify);
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
pgPlugin(fastify);
|
|
87
|
+
sqlitePlugin(fastify);
|
|
87
88
|
cronPlugin();
|
|
88
89
|
loggerPlugin(fastify);
|
|
89
90
|
if (config.rateLimit !== false) {
|
|
90
|
-
|
|
91
|
+
fastify.register(import("@fastify/rate-limit"), {
|
|
91
92
|
max: parseInt(config.rateLimit?.max || 100),
|
|
92
93
|
timeWindow: config.rateLimit?.timeWindow || 60000,
|
|
93
94
|
hook: "preHandler",
|
|
@@ -111,7 +112,7 @@ async function plugin(fastify) {
|
|
|
111
112
|
fastify.register(templatesRoutes, opt);
|
|
112
113
|
fastify.register(authRoutes); // from fastify-auth
|
|
113
114
|
// from fastify-file
|
|
114
|
-
|
|
115
|
+
fastify.register(import("@fastify/multipart"), {
|
|
115
116
|
limits: {
|
|
116
117
|
fileSize: maxFileSize * 1024 * 1024,
|
|
117
118
|
},
|
|
@@ -163,4 +164,4 @@ async function plugin(fastify) {
|
|
|
163
164
|
}
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
|
-
export default plugin;
|
|
167
|
+
export default fp(plugin);
|
|
@@ -7,22 +7,22 @@ import config from "../../../config.js";
|
|
|
7
7
|
import getRedis from "../redis/funcs/getRedis.js";
|
|
8
8
|
const fastifyPassport = new Authenticator();
|
|
9
9
|
const { prefix = "/api" } = config;
|
|
10
|
-
|
|
10
|
+
function plugin(fastify) {
|
|
11
11
|
if (!config.redis) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
fastify.register(cookie, {
|
|
15
15
|
parseOptions: config?.auth?.cookieOptions || { secure: false },
|
|
16
16
|
});
|
|
17
|
-
|
|
17
|
+
fastify.register(session, {
|
|
18
18
|
secret: config?.auth?.secret || "61b820e12858570a4b0633020d4394a17903d9a9",
|
|
19
19
|
cookieName: "session_auth",
|
|
20
20
|
cookie: config?.auth?.cookieOptions || { secure: false },
|
|
21
21
|
store: new RedisStore({ client: getRedis({ db: 10 }) }),
|
|
22
22
|
});
|
|
23
23
|
// register passport AFTER session is ready
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
fastify.register(fastifyPassport.initialize());
|
|
25
|
+
fastify.register(fastifyPassport.secureSession());
|
|
26
26
|
// serialize user used to store user info in session store
|
|
27
27
|
fastifyPassport.registerUserSerializer(async (user) => ({ user }));
|
|
28
28
|
// deserialize user used to add user info from session store to req
|
|
@@ -22,10 +22,10 @@ async function getHeadersPG(req) {
|
|
|
22
22
|
}
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
const client = await getPGAsync({ ...(config.pg || {}), name: "client" });
|
|
25
|
+
function plugin(fastify) {
|
|
27
26
|
fastify.addHook("onRequest", async (req) => {
|
|
28
27
|
const headersPG = await getHeadersPG(req);
|
|
28
|
+
const client = await getPGAsync({ ...(config.pg || {}), name: "client" });
|
|
29
29
|
req.pg = headersPG || req.pg || client || pgClients.client;
|
|
30
30
|
if (headersPG) {
|
|
31
31
|
req.user = { uid: req.headers?.uid };
|