0

I have below route to return privacy policy for my app.

const html = `<html><body><div>dsfdsfsfdsfsfsdfdsf</div></body></html>`
const handler = (request, reply) => {
  try {
    return reply(html)
  } catch (err) {
    return reply({ success: false, message: err.message, data: [] })
  }
}

const routeConfig = {
  method: 'GET',
  path: '/privacy-policy',
  config: {
    description: 'Creates a task.',
    notes: ['On success, returns { "data": [ { "tasks" } ]}'],
    handler
  }
}

However when I am returning the html content I am getting double quotes at the start and at the end of my content.

How can I remove them? Thank you

Profer
  • 553
  • 8
  • 40
  • 81

3 Answers3

0

You can do two things here -

// 1. You can reply with html as json`
return reply({html});

// This will this html in a json and you can use this in frontend receiving a json response 
// 2. You can send the html (file) as a html response
return reply.view('htmlFile.html');
//If you want to render the html
Rahul
  • 863
  • 6
  • 23
0

You are getting quotes in start and end of the html because of you are returning it as string. What you can do is, rather returning the replay in the string you can return the Html. One more thing is not to forget the response header Content-Type as text/html. once you set the response header, the client browser will understand the response and start parsing it.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
0

I think you just forgot to set Content-Type to text/html.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81