Skip to content

Commit f1e0b5e

Browse files
Fix syntax error in adjustEndpoints.js
Remove duplicate code that was causing SyntaxError on Firewalla
1 parent 059100d commit f1e0b5e

1 file changed

Lines changed: 6 additions & 30 deletions

File tree

src/controllers/adjustEndpoints.js

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function adjustEndpoints(req, res) {
1515
const acceptHeader = req.get('Accept');
1616

1717
logger.debug('Adjust endpoints request received', {
18-
count: (endpoints || []).length,
18+
count: Array.isArray(endpoints) ? endpoints.length : 0,
1919
accept: acceptHeader
2020
});
2121

@@ -25,36 +25,12 @@ function adjustEndpoints(req, res) {
2525
return res.status(406).json({ error: 'Not Acceptable' });
2626
}
2727

28-
// Validate request body
28+
// Validate input
2929
if (!Array.isArray(endpoints)) {
30-
logger.warn('Invalid request body for adjust endpoints');
31-
return res.status(400).json({ error: 'Invalid request body' });
30+
logger.warn('Invalid request body for adjust endpoints (not an array)');
31+
return res.status(400).json({ error: 'Request body must be an array of endpoints' });
3232
}
3333

34-
// Filter out unsupported record types
35-
// We only support A and TXT records
36-
const filtered = endpoints.filter(endpoint => {
37-
const supported = SUPPORTED_RECORD_TYPES.has(endpoint.recordType);
38-
if (!supported) {
39-
logger.debug('Filtering out unsupported record type', {
40-
dnsName: endpoint.dnsName,
41-
recordType: endpoint.recordType
42-
});
43-
}
44-
return supported;
45-
});
46-
47-
logger.info('Adjust endpoints completed', {
48-
input: endpoints.length,
49-
output: filtered.length,
50-
filtered: endpoints.length - filtered.length
51-
});
52-
53-
// Set exact content type (no charset) for external-dns webhook protocol
54-
res.setHeader('Content-Type', config.contentType);
55-
res.send(JSON.stringify(filtered));
56-
}
57-
5834
// Filter endpoints:
5935
// 1. Keep only A and TXT record types
6036
// 2. Remove invalid endpoints
@@ -93,9 +69,9 @@ function adjustEndpoints(req, res) {
9369
filteredCount: endpoints.length - adjustedEndpoints.length
9470
});
9571

96-
// Set content type for external-dns webhook protocol
72+
// Set exact content type (no charset) for external-dns webhook protocol
9773
res.setHeader('Content-Type', config.contentType);
98-
res.json(adjustedEndpoints);
74+
res.send(JSON.stringify(adjustedEndpoints));
9975
}
10076

10177
module.exports = adjustEndpoints;

0 commit comments

Comments
 (0)