api.js 641 Bytes
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1 2 3 4 5 6 7 8
// [START functions import]
const express = require('express');
const serverLess = require('serverless-http');

const matchMock = require('./mock/matchMock');

const app = express();

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
app.all('*', (req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header(
    'Access-Control-Allow-Headers',
    'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild',
  );
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

  if (req.method == 'OPTIONS') {
    res.send(200);
  } else {
    next();
  }
});

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
24 25 26
app.use(matchMock);

exports.handler = serverLess(app);