File size: 531 Bytes
bbfde3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const { applyCorsHeaders, handleCorsPreflight } = require('../lib/cors-middleware');

module.exports = async (req, res) => {
  if (handleCorsPreflight(req, res, { allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS' })) {
    return;
  }
  applyCorsHeaders(req, res, { allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS' });

  res.setHeader('Content-Type', 'application/json');
  
  if (req.method === 'OPTIONS') {
    return res.status(200).end();
  }
  
  return res.status(200).end(JSON.stringify({ ok: true }));
};