From 1a923d5f8c0835078415199c8d01868a8c1c75d9 Mon Sep 17 00:00:00 2001 From: Luciano Fantone Date: Thu, 11 Jan 2024 15:45:00 +0100 Subject: [PATCH] fix(adapter): add support for async load context --- CHANGELOG.md | 13 +++---------- src/server.js | 4 ++-- src/server.test.js | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f5a39..8d545e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,10 @@ # 1.0.0 (2024-01-11) - ### Bug Fixes -* **deps:** upgrade node dependencies 73e74c2 -* **remix-adapter:** update jsdocs and types da375a7 - +- **deps:** upgrade node dependencies 73e74c2 +- **remix-adapter:** update jsdocs and types da375a7 ### Features -* **adapter:** implement remix.run azure adapter 1cdaa77 -* **create-remix-azure-adapter:** support asynchronous getLoadContext f1503b3 -* **create-remix-azure-adapter:** support asynchronous getLoadContext 90da3a2 -* **packages:** add the create-remix-azure-adapter package ([#58](https://github.com/scandinavianairlines/remix-azure-functions/issues/58)) 033c5ce -* **rename:** remove 'adg' prefix from package name c197b97 -* **types:** generate types on pre-publish 6ea55aa +- **adapter:** implement remix.run azure adapter 1cdaa77 diff --git a/src/server.js b/src/server.js index 8dc4d3d..a4d614d 100644 --- a/src/server.js +++ b/src/server.js @@ -9,7 +9,7 @@ import { isBinaryType } from './is-binary-type.js'; installGlobals(); /** - * @typedef {(request: import('@azure/functions').HttpRequest, context: import('@azure/functions').InvocationContext) => import('@remix-run/node').AppLoadContext} GetLoadContextFn + * @typedef {(request: import('@azure/functions').HttpRequest, context: import('@azure/functions').InvocationContext) => Promise} GetLoadContextFn */ /** @@ -98,7 +98,7 @@ export function createRequestHandler(options) { * @returns {Promise} A Azure Function `http response init` object. */ async function functionHandler(request, context) { - const loadContext = options.getLoadContext?.(request, context); + const loadContext = await options.getLoadContext?.(request, context); const remixRequest = createRemixRequest(request, { urlParser: options.urlParser }); const remixResponse = await handler(remixRequest, loadContext); diff --git a/src/server.test.js b/src/server.test.js index b926dc1..5d4f5da 100644 --- a/src/server.test.js +++ b/src/server.test.js @@ -112,7 +112,7 @@ describe('server', () => { params: undefined, url: 'https://test.com', }); - const mockGetLoadContext = vi.fn(); + const mockGetLoadContext = vi.fn().mockResolvedValue({}); const mockAzureContext = { log: vi.fn() }; createRemixRequestHandler.mockReturnValue(mockHandler); const handler = createRequestHandler({