Skip to content
Foxipa
Code Completion 5 Challenges

Complete the code: CORS Server-Side

Fill in the missing response headers a credentialed beacon collector must send.

Intermediate ~4 min read

Challenge 1

Echo the caller's origin — never the wildcard.

js Your answer
app.use((req, res, next) => {
  res.setHeader('Access-Control-Allow-Origin', ;
});

Press Ctrl⌘Enter to check your answer

Challenge 2

Permit the credentialed request with the literal value.

js Your answer
res.setHeader('Access-Control-Allow-Credentials', '');

Press Ctrl⌘Enter to check your answer

Challenge 3

Stop shared caches from leaking one origin's allowance to another.

js Your answer
res.setHeader('', 'Origin');

Press Ctrl⌘Enter to check your answer

Challenge 4

Answer the preflight for the method beacons use.

js Your answer
if (req.method === 'OPTIONS') {
  res.setHeader('Access-Control-Allow-Methods', '');
  return res.sendStatus(204);
}

Press Ctrl⌘Enter to check your answer

Challenge 5

The beacon-idiomatic response status.

js Your answer
// fire-and-forget: the server is encouraged to reply with
res.sendStatus();

Press Ctrl⌘Enter to check your answer