How to use the micro.send function in micro

To help you get started, we’ve selected a few micro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dangdennis / list / api / node / getWishes.js View on Github external
ddb.scan(params, function(err, data) {
    if (err) {
      send(res, 500, err);
    } else {
      // res.Items is returned as an array
      if (data.Items && data.Items.length) {
        // Unmarshall, aka reformat, the results to regular JSON format
        let unmarshalled = data.Items.map(item =>
          AWS.DynamoDB.Converter.unmarshall(item)
        );
        data.Items = unmarshalled; // We want to keep the other data points from DynamoDB
      }
      send(res, 200, data);
    }
  });
};
github Yoctol / bottender / packages / bottender-micro / src / verifyMessengerWebhook.js View on Github external
const verifyMessengerWebhook = ({ verifyToken }) => (req, res) => {
  const { query } = url.parse(req.url, true);
  if (
    query['hub.mode'] === 'subscribe' &&
    query['hub.verify_token'] === verifyToken
  ) {
    send(res, 200, query['hub.challenge']);
  } else {
    console.error('Failed validation. Make sure the validation tokens match.');
    send(res, 403);
  }
};
github coljs / workshop-microservices-micro / save / image-save.js View on Github external
module.exports = async function (req, res) {
  const body = await json(req)
  const { name, filter } = body

  let image, result
  try {
    image = await convert(name, filter)
    result = await s3move(name, image)
  } catch (e) {
    console.log(e.stack)
    return send(res, 500, e.message)
  }

  send(res, 200, { name: name, src: result.Location })
}
github dangdennis / list / api / node / putWish.js View on Github external
ddb.putItem(params, (err, data) => {
      if (err) {
        console.log('Error', err);
        send(res, 500, err);
      } else {
        console.log('Success', data);
        send(res, 200, { ...data, user_id: uniqueId, name: data.name });
      }
    });
  } catch (e) {
github dannav / now-compose / examples / cluster / web / index.js View on Github external
const server = micro(async (req, res) => {
  try {
    const people = await getData(peopleAPIURL)
    const locations = await getData(locationsAPIURL)

    return send(res, 200, {
      readme,
      people,
      locations
    })
  } catch (err) {
    return send(res, 500, 'Internal Server Error')
  }
})
github prismyland / prismy / src / results / SendResult.ts View on Github external
handle({ res }: Context) {
    this.headers.forEach(([key, value]) => {
      res.setHeader(key, value)
    })

    send(res, this.statusCode, this.data)
  }
}
github coljs / workshop-microservices-micro / preview / image-preview.js View on Github external
module.exports = async function (req, res) {
  const body = await json(req)
  const { name, filter } = body

  const type = mime.lookup(name)

  let preview
  try {
    preview = await convert(name, filter)
  } catch (e) {
    send(res, 500, e.message)
  }

  const imagePreview = `data:${type};base64,${preview.toString('base64')}`
  send(res, 200, { image: imagePreview })
}
github drex44 / good-food-guide / api / getAllDiseases / index.js View on Github external
.then(function(docs) {
      if (docs.length == 0) send(res, statusCode, { error: "No record found" });
      else send(res, statusCode, docs);
    })
    .catch(function(err) {
github drex44 / good-food-guide / api / getDisease / index.js View on Github external
.then(function(docs) {
      if (docs.length == 0) send(res, statusCode, { error: "No record found" });
      else send(res, statusCode, docs);
    })
    .catch(function(err) {
github perliedman / elevation-service / index.js View on Github external
addElevation(geojson, tiles, function(err, geojson) {
      if (err) {
        return send(res, 500, err)
      }

      resolve(geojson)
    }, noData)
  })

micro

Asynchronous HTTP microservices

MIT
Latest version published 2 years ago

Package Health Score

63 / 100
Full package analysis