@11ty/eleventy-dev-server
Advanced tools
Comparing version 1.0.0-canary.4 to 1.0.0-canary.5
{ | ||
"name": "@11ty/eleventy-dev-server", | ||
"version": "1.0.0-canary.4", | ||
"version": "1.0.0-canary.5", | ||
"description": "A minimal, modern, generic, hot-reloading local web server to help web developers.", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -229,2 +229,19 @@ const pkg = require("./package.json"); | ||
renderFile(filepath, res) { | ||
let contents = fs.readFileSync(filepath); | ||
let mimeType = mime.getType(filepath); | ||
if (mimeType === "text/html") { | ||
res.setHeader("Content-Type", `text/html; charset=${this.options.encoding}`); | ||
// the string is important here, wrapResponse expects strings internally for HTML content (for now) | ||
return res.end(contents.toString()); | ||
} | ||
if (mimeType) { | ||
res.setHeader("Content-Type", mimeType); | ||
} | ||
return res.end(contents); | ||
} | ||
requestMiddleware(req, res) { | ||
@@ -265,23 +282,18 @@ // Known issue with `finalhandler` and HTTP/2: | ||
if (match.statusCode === 200 && match.filepath) { | ||
let contents = fs.readFileSync(match.filepath); | ||
let mimeType = mime.getType(match.filepath); | ||
if (mimeType === "text/html") { | ||
res.setHeader("Content-Type", `text/html; charset=${this.options.encoding}`); | ||
// the string is important here, wrapResponse expects strings internally for HTML content (for now) | ||
return res.end(contents.toString()); | ||
} | ||
return this.renderFile(match.filepath, res); | ||
} | ||
if (mimeType) { | ||
res.setHeader("Content-Type", mimeType); | ||
} | ||
return res.end(contents); | ||
let raw404Path = this.getOutputDirFilePath("404.html"); | ||
if(match.statusCode === 404 && this.isOutputFilePathExists(raw404Path)) { | ||
res.statusCode = match.statusCode; | ||
return this.renderFile(raw404Path, res); | ||
} | ||
// TODO add support for 404 pages (in different Jamstack server configurations) | ||
// Redirects | ||
if (match.url) { | ||
res.writeHead(match.statusCode, { | ||
Location: match.url, | ||
}); | ||
res.statusCode = match.statusCode; | ||
res.setHeader("Location", match.url); | ||
return res.end(); | ||
} | ||
} | ||
@@ -288,0 +300,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26228
670