Example #1
0
export default async function (req, res) {
    if (req.url.match(isStaticAsset)) {
        return send(res, 200, await serveStatic(req.url))
    }

    const tmpl = await serveStatic('index.html')
    const completeData = rawToArray(await readFileAsync(`${__dirname}/sensor_data`))
    const lastDayData = filter.lastDay(completeData)

    const data = toChartData(lastDayData)

    return send(res, 200, tmpl.replace(/window.__data__/g, JSON.stringify(data)))
}
Example #2
0
  const fn = async (req, res) => {
    const stream = resumer().queue('error-stream')
    send(res, 200, stream)

    stream.emit('error', new Error('500 from test (expected)'))
    stream.end()
  }
export default async function (req, res) {
  try {
    // Get symbols
    let symbols = await getSymbols()

    // Create fetch symbols promise array
    let fetchQuotes = symbols.map(getQuote)

    // Fetch all quotes
    let quotes = await Promise.all(fetchQuotes)

    // Create save quotes promise array
    let saveQuotes = quotes.map((elem) => saveQuote(elem.symbol, elem.quote))

    // Save all quotes
    await Promise.all(saveQuotes)

    let results = quotes.map(elem => elem.quote)

    send(res, 200, results)
  } catch (err) {
    send(res, 500, err.message)
  }
}
Example #4
0
 const fn = async (req, res) => {
   send(res, 200, 'woot')
 }
Example #5
0
 const fn = async (req, res) => {
   send(res, 404)
 }
Example #6
0
 const fn = async (req, res) => {
   send(res, 200, resumer().queue('waterfall').end())
 }
Example #7
0
 const fn = async (req, res) => {
   const body = await json(req, { limit: 3 })
   send(res, 200, { response: body.some.cool })
 }
Example #8
0
 const fn = (req, res) => {
   send(res, 200, { a: 'b' })
 }
Example #9
0
 const fn = async (req, res) => {
   const obj = { circular: true }
   obj.obj = obj
   send(res, 200, obj)
 }
Example #10
0
 const fn = async (req, res) => {
   send(res, 200, new Buffer('muscle'))
 }
Example #11
0
 const fn = async (req, res) => {
   const body = await json(req)
   send(res, 200, body.woot)
 }
Example #12
0
 const onError = async (req, res, err) => {
   await sleep(50)
   send(res, 200, 'got async error')
 }
Example #13
0
 const onError = (req, res, err) => {
   send(res, 200, 'got error')
 }