Skip to content

Commit 21fd8c1

Browse files
committed
fix: fix server actions in Node.js
1 parent 88e7e6a commit 21fd8c1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/brisa/src/utils/response-action/index.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'bun:test';
1010
import path from 'node:path';
1111
import extendRequestContext from '@/utils/extend-request-context';
12-
import responseAction from '.';
12+
import responseAction, { getActionFile } from '.';
1313
import { getConstants } from '@/constants';
1414
import { ENCRYPT_NONTEXT_PREFIX, encrypt } from '@/utils/crypto';
1515
import { boldLog } from '@/utils/log/log-color';
@@ -847,4 +847,10 @@ describe('utils', () => {
847847
expect(await res.text()).toBe(JSON.stringify([['foo', 'bar']]));
848848
});
849849
});
850+
851+
describe('getActionFile', () => {
852+
it('should return the file with the .js extension to work in Node.js and Bun.js', () => {
853+
expect(getActionFile('a1_1')).toBe('a1.js');
854+
});
855+
});
850856
});

packages/brisa/src/utils/response-action/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default async function responseAction(req: RequestContext) {
1616
const action =
1717
req.headers.get('x-action') ?? url.searchParams.get('_aid') ?? '';
1818
const actionsHeaderValue = req.headers.get('x-actions') ?? '[]';
19-
const actionFile = action.split('_').at(0);
19+
const actionFile = getActionFile(action);
2020
const actionModule = await import(join(BUILD_DIR, 'actions', actionFile!));
2121
let resetForm = false;
2222

@@ -202,3 +202,7 @@ export default async function responseAction(req: RequestContext) {
202202

203203
return response;
204204
}
205+
206+
export function getActionFile(action: string) {
207+
return action.split('_').at(0) + '.js';
208+
}

0 commit comments

Comments
 (0)