Verified Commit c7c49a3e authored by Aral Balkan's avatar Aral Balkan
Browse files

Replace response.type('html').end() with response.html()

  - In readme examples
  - In unit test fixtures
parent 8db1a6dc
......@@ -797,8 +797,7 @@ let counter = 0
module.exports = (request, response) => {
response
.type('html')
.end(`
.html(`
<h1>Hello, world!</h1>
<p>I’ve been called ${++counter} time${counter > 1 ? 's': ''} since the server started.</p>
`)
......@@ -826,9 +825,7 @@ function serverStats (request, response) {
const page = `<html><head><title>Server statistics</title><style>body {font-family: sans-serif;}</style></head><body><h1>Server statistics</h1><h2>Load averages</h2>${loadAverages}<h2>Free memory</h2>${freeMemory}</body></html>`
response
.type('html')
.end(page)
response.html(page)
}
module.exports = serverStats
......@@ -889,29 +886,27 @@ module.exports = function (request, response) {
return `#${c()}${c()}${c()}`
}
response
.type('html')
.end(`
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Cows!</title>
<style>
html { font-family: sans-serif; color: dark-grey; background-color: ${randomColor()}; }
body {
display: grid; align-items: center; justify-content: center;
height: 100vh; vertical-align: top; margin: 0;
}
pre { font-size: 24px; color: ${randomColor()}; mix-blend-mode: difference;}
</style>
</head>
<body>
<pre>${randomCow}</pre>
</body>
</html>
`)
response.html(`
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Cows!</title>
<style>
html { font-family: sans-serif; color: dark-grey; background-color: ${randomColor()}; }
body {
display: grid; align-items: center; justify-content: center;
height: 100vh; vertical-align: top; margin: 0;
}
pre { font-size: 24px; color: ${randomColor()}; mix-blend-mode: difference;}
</style>
</head>
<body>
<pre>${randomCow}</pre>
</body>
</html>
`)
}
```
......@@ -1002,7 +997,7 @@ module.exports = function (request, response) {
// … because the HTML template references the rendered CSS template.
const html = render(htmlTemplate)
response.type('html').end(html)
response.html(html)
}
```
......@@ -1119,9 +1114,7 @@ The _routes.js_ file should export a function that accepts a reference to the Ex
module.exports = app => {
// HTTPS route with a parameter called thing.
app.get('/hello/:thing', (request, response) => {
response
.type('html')
.end(`<h1>Hello, ${request.params.thing}!</h1>`)
response.html(`<h1>Hello, ${request.params.thing}!</h1>`)
})
// WebSocket route: echos messages back to the client that sent them.
......
......@@ -6,23 +6,21 @@ function paveTheCowPaths(request, response, next) {
const randomCowIndex = Math.round(Math.random()*cows.length)-1
const randomCow = cows[randomCowIndex]
response
.type('html')
.end(`
<!doctype html>
<html lang="en" style="font-family: sans-serif; background-color: #eae7e1">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cows!</title>
</head>
<body style="display: grid; align-items: center; justify-content: center; height: 100vh; vertical-align: top; margin: 0;">
<main>
<pre style="font-size: 24px;">${randomCow}</pre>
</main>
</body>
</html>
`)
response.html(`
<!doctype html>
<html lang="en" style="font-family: sans-serif; background-color: #eae7e1">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cows!</title>
</head>
<body style="display: grid; align-items: center; justify-content: center; height: 100vh; vertical-align: top; margin: 0;">
<main>
<pre style="font-size: 24px;">${randomCow}</pre>
</main>
</body>
</html>
`)
}
module.exports = paveTheCowPaths
module.exports = (request, response) => {
response.type('html').status(200).end('<h1>deep/deeper.js (masked by deep/deeper/index.js so you should never see this)</h1>')
response.html('<h1>deep/deeper.js (masked by deep/deeper/index.js so you should never see this)</h1>')
}
module.exports = (request, response) => {
response.type('html').status(200).end('<h1>Deeper index</h1>')
response.html('<h1>Deeper index</h1>')
}
module.exports = (request, response) => {
response.type('html').status(200).end('<h1>A deep route</h1>')
response.html('<h1>A deep route</h1>')
}
......@@ -9,20 +9,18 @@ function markdown (request, response, next) {
- Of
- Fun!
`)
response
.type('html')
.end(`
<!doctype html>
<html lang="en" style="font-family: sans-serif; background-color: #eae7e1">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Example</title>
</head>
<body style="display: grid; align-items: center; justify-content: center; height: 100vh; vertical-align: top; margin: 0;">
<main style="font-size: 2rem;">${html}</main>
</body>
</html>
`)
response.html(`
<!doctype html>
<html lang="en" style="font-family: sans-serif; background-color: #eae7e1">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Example</title>
</head>
<body style="display: grid; align-items: center; justify-content: center; height: 100vh; vertical-align: top; margin: 0;">
<main style="font-size: 2rem;">${html}</main>
</body>
</html>
`)
}
module.exports = markdown
......@@ -23,7 +23,7 @@ function serverStats (request, response, next) {
</html>
`
response.type('html').end(page)
response.html(page)
}
module.exports = serverStats
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment