lite-web-server
Advanced tools
Comparing version 1.0.10-beta.1633569780 to 1.0.10
@@ -12,2 +12,3 @@ # Change Log | ||
- options.req405error and options.notfound are changed to options.errordocument._404 and options.errordocument._405 | ||
- default 404 and 405 pages are improved. | ||
@@ -14,0 +15,0 @@ ### Fixed |
@@ -0,0 +0,0 @@ var { WebServer } = require("./index.js"); |
@@ -28,3 +28,3 @@ { | ||
"better-docs": { | ||
"name": "lite-web-server v1.0.10-beta.1633569780", | ||
"name": "lite-web-server v1.0.10", | ||
"title": "lite-web-server Documentation", | ||
@@ -31,0 +31,0 @@ "css": "/style.css", |
@@ -13,4 +13,4 @@ const http = require('http'); | ||
* @property {boolean} [options.acceptonlyget=true] - Only accepts get request. | ||
* @property {string} [options.errordocument._404=`${__dirname}../assets/def_pages/404.html`] - Html file path to respond on the request methods other than GET. | ||
* @property {string} [options.errordocument._405=`${__dirname}../assets/def_pages/405.html`] - Html file path to respond on not found. | ||
* @property {string} [options.errordocument._404=`${__dirname}/assets/def_pages/404.html`] - Html file path to respond on the request methods other than GET. | ||
* @property {string} [options.errordocument._405=`${__dirname}/assets/def_pages/405.html`] - Html file path to respond on not found. | ||
* @property {boolean} [options.useindexhtml=true] - If it's true, returns ./index.html file when requested directory. | ||
@@ -35,20 +35,24 @@ * @property {string} [options.rootfile=/index.html] - You can specify a file to load as a top page. (Please specify files in the published directory.) | ||
constructor(opts) { | ||
async function run(opts) { | ||
this.opts = opts; | ||
if (opts) { | ||
var error_doc404 = opts.errordocument._404 || `${__dirname}../assets/def_pages/404.html`; | ||
var error_doc405 = opts.errordocument._405 || `${__dirname}../assets/def_pages/405.html`; | ||
this.opts = run(opts); | ||
function run(options) { | ||
if (options) { | ||
if (!options.errordocument) { | ||
options.errordocument = {}; | ||
} | ||
var error_doc404 = options.errordocument._404 || `${__dirname}/assets/def_pages/404.html`; | ||
var error_doc405 = options.errordocument._405 || `${__dirname}/assets/def_pages/405.html`; | ||
try { | ||
var _404 = await fs.readFileSync(error_doc404); | ||
var _404 = fs.readFileSync(error_doc404); | ||
} catch (error) { | ||
console.error(new Error(`Invailed 404 error file location "${error_doc404}". Default location will used.`)); | ||
opts.errordocument._404 = `${__dirname}../assets/def_pages/404.html`; | ||
options.errordocument._404 = `${__dirname}/assets/def_pages/404.html`; | ||
} | ||
try { | ||
var _405 = await fs.readFileSync(error_doc405); | ||
var _405 = fs.readFileSync(error_doc405); | ||
} catch (error) { | ||
console.error(new Error(`Invailed 405 error file location "${error_doc405}". Default location will used.`)); | ||
opts.errordocument._405 = `${__dirname}../assets/def_pages/405.html`; | ||
options.errordocument._405 = `${__dirname}/assets/def_pages/405.html`; | ||
} | ||
} | ||
return options; | ||
} | ||
@@ -76,4 +80,4 @@ | ||
errordocument: { | ||
_404: `${__dirname}../assets/def_pages/404.html`, | ||
_405: `${__dirname}../assets/def_pages/405.html` | ||
_404: `${__dirname}/assets/def_pages/404.html`, | ||
_405: `${__dirname}/assets/def_pages/405.html` | ||
} | ||
@@ -105,2 +109,5 @@ } | ||
} | ||
if (!opt.errordocument) { | ||
opt.errordocument = {}; | ||
} | ||
var options = { | ||
@@ -115,4 +122,4 @@ directory: dir || "./public", | ||
errordocument: { | ||
_404: options.errordocument._404 || `${__dirname}../assets/def_pages/404.html`, | ||
_405: options.errordocument._405 || `${__dirname}../assets/def_pages/405.html` | ||
_404: opt.errordocument._404 || `${__dirname}/assets/def_pages/404.html`, | ||
_405: opt.errordocument._405 || `${__dirname}/assets/def_pages/405.html` | ||
} | ||
@@ -157,5 +164,5 @@ } | ||
var read_file = await fs.readFileSync(options.errordocument._404).toString(); | ||
var file = read_file.replace(/<!--${404URL}-->/g, `${url}`); | ||
var file = read_file.replace(/<!--\${404URL}-->/g, `${url}`); | ||
res.writeHead(404, { "Content-Type": "text/html" }); | ||
res.end(options.notfound); | ||
res.end(file); | ||
} catch (error) { | ||
@@ -162,0 +169,0 @@ res.writeHead(500, { "Content-Type": "text/html" }); |
{ | ||
"name": "lite-web-server", | ||
"version": "1.0.10-beta.1633569780", | ||
"version": "1.0.10", | ||
"description": "creates simple web server.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,0 +0,0 @@ # lite-web-server |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
172996
413
0