fastify-txstate 3.3.1 → 3.3.3
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/lib/index.d.ts +2 -0
- package/lib/index.js +4 -2
- package/lib/unified-auth.js +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export interface FastifyTxStateOptions extends Partial<FastifyServerOptions> {
|
|
|
82
82
|
declare module 'fastify' {
|
|
83
83
|
interface FastifyRequest {
|
|
84
84
|
auth?: FastifyTxStateAuthInfo;
|
|
85
|
+
token?: string;
|
|
85
86
|
}
|
|
86
87
|
interface FastifyReply {
|
|
87
88
|
extraLogInfo: any;
|
|
@@ -132,6 +133,7 @@ export default class Server {
|
|
|
132
133
|
protected validOrigins: Record<string, boolean>;
|
|
133
134
|
protected validOriginHosts: Record<string, boolean>;
|
|
134
135
|
protected validOriginSuffixes: Set<string>;
|
|
136
|
+
protected swaggerEndpoint: string | undefined;
|
|
135
137
|
app: FastifyInstanceTyped;
|
|
136
138
|
constructor(config?: FastifyTxStateOptions & {
|
|
137
139
|
http2?: true;
|
package/lib/index.js
CHANGED
|
@@ -73,6 +73,7 @@ class Server {
|
|
|
73
73
|
validOrigins = {};
|
|
74
74
|
validOriginHosts = {};
|
|
75
75
|
validOriginSuffixes = new Set();
|
|
76
|
+
swaggerEndpoint;
|
|
76
77
|
app;
|
|
77
78
|
constructor(config = {}) {
|
|
78
79
|
this.config = config;
|
|
@@ -210,7 +211,7 @@ class Server {
|
|
|
210
211
|
DELETE: true
|
|
211
212
|
};
|
|
212
213
|
this.app.addHook('onRequest', async (req, res) => {
|
|
213
|
-
if (!authenticatedMethods[req.method] || req.routeOptions.url === '/health')
|
|
214
|
+
if (!authenticatedMethods[req.method] || req.routeOptions.url === '/health' || (this.swaggerEndpoint && req.routeOptions.url?.startsWith(this.swaggerEndpoint)))
|
|
214
215
|
return;
|
|
215
216
|
try {
|
|
216
217
|
req.auth = await config.authenticate(req);
|
|
@@ -394,7 +395,8 @@ this is log into this application and use dev tools to pull your token from the
|
|
|
394
395
|
return { schema: newSchema, url, route, swaggerObject, openapiObject };
|
|
395
396
|
}
|
|
396
397
|
});
|
|
397
|
-
|
|
398
|
+
this.swaggerEndpoint = opts?.path ?? opts?.ui?.routePrefix ?? '/docs';
|
|
399
|
+
await this.app.register(swagger_ui_1.default, { ...opts?.ui, routePrefix: this.swaggerEndpoint });
|
|
398
400
|
}
|
|
399
401
|
async close(softSeconds) {
|
|
400
402
|
if (typeof softSeconds === 'undefined')
|
package/lib/unified-auth.js
CHANGED