Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavoyan committed Jul 1, 2024
1 parent 5134925 commit 7a682ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/sample-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const build = (opts: buildOpts = {}): FastifyInstance => {
app.addSchema(presentationRequestSchema);
app.addSchema(errorSchema);

app.register(vclSdkPlugin);

app.register(autoload, {
dir: path.join(__dirname, "routes"),
});

app.register(vclSdkPlugin);

return app;
};

Expand Down
21 changes: 14 additions & 7 deletions packages/sample-server/src/plugins/vclSdkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { CurrentEnvironment, XVnfProtocolVersion } from "../global-config";

const vclSdkPlugin: FastifyPluginAsync | FastifyPluginCallback = async (
fastify,
fastify
) => {
const vclSdk = VCLProvider.getInstance();

Expand All @@ -41,12 +41,19 @@ const vclSdkPlugin: FastifyPluginAsync | FastifyPluginCallback = async (
console.error('Failed to initialize VCL SDK', e);
throw e;
}
fastify.decorate('vclSdk', vclSdk)
fastify.addHook('preHandler', function (req, reply, done) {
req.vclSdk = vclSdk
reply.vclSdk = vclSdk
done()
})
fastify
.decorate('vclSdk', vclSdk)
.decorateRequest('vclSdk', null)
.addHook('preHandler', async (req, reply, done) => {
req.vclSdk = fastify.vclSdk
reply.vclSdk = fastify.vclSdk
done()
})
.addHook('preValidation', async (req, reply, done) => {
req.vclSdk = fastify.vclSdk
reply.vclSdk = fastify.vclSdk
done()
});
};

export default vclSdkPlugin;

0 comments on commit 7a682ba

Please sign in to comment.