Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function loadServerConfig(): Promise<ServerConfig | null> {

let parsed: unknown;
try {
parsed = JSON.parse(raw);
parsed = JSON.parse(raw.replace(/^\uFEFF/, ''));
} catch (err) {
console.error(`[config] Failed to load config: ${(err as Error).message}`);
return null;
Expand Down
14 changes: 14 additions & 0 deletions tests/server-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ describe('loadServerConfig', () => {
});
});

it('loads project roots and the HTTP port from a config with a UTF-8 BOM', async () => {
const config = JSON.stringify({
projects: [{ root: 'example-project' }],
server: { port: 4242 }
});
await withTempConfig(`\uFEFF${config}`, async (filePath) => {
process.env.CODEBASE_CONTEXT_CONFIG_PATH = filePath;
expect(await loadServerConfig()).toEqual({
projects: [{ root: path.resolve('example-project') }],
server: { port: 4242 }
});
});
});

it('returns null when top-level value is an array', async () => {
await withTempConfig('[]', async (filePath) => {
process.env.CODEBASE_CONTEXT_CONFIG_PATH = filePath;
Expand Down
Loading