Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created February 1, 2019 00:44
Show Gist options
  • Save brianleroux/d239e158f2ce8305acbd5110648fa2a7 to your computer and use it in GitHub Desktop.
Save brianleroux/d239e158f2ce8305acbd5110648fa2a7 to your computer and use it in GitHub Desktop.
maaaaabye this?
let next = require('../../front/.next/serverless/pages/index.js')
exports.handler = async function http(req) {
req.url = req.path
let res = {end(){},setHeader(){}}
return {type:'text/html; charset=utf8', body: next.render(req,res).html}
}
@agstover
Copy link

agstover commented Feb 1, 2019

Running that I can see that the renderReqToHTML function in Next does get the html string, but it's not showing up on the page or in the end(){} function.

I wrote this which is janky as heck, but it gets the right html to the browser. The right html makes it to the res.end() function, but nothing returns. I'm not sure how to mock the real res.end() function

exports.handler = async function http(req) {
  let html
  let res = {
    method: 'GET',
    headers: [],
    statusCode: 400,
    getHeader: (val) => {
      console.log("getHeader", val)
      return true
    },
    setHeader: (header, content) => {
      this[header] = content
      console.log("this is header", header)
      return header
    },
    end: (end) => {
      console.log("This is what end gets", end)
      html = end
      return end
    }
  }
  req.url = req.path
  const body = await next.render(req, res)
  console.log("this is body", body)
  return {
    type: 'text/html; charset=utf8',
    body: html
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment