pico-static-server
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -1,2 +0,2 @@ | ||
const createServer = require('pico-static-server'); | ||
const createServer = require('./../index.js'); | ||
@@ -3,0 +3,0 @@ const staticServer = createServer({ |
@@ -1,8 +0,8 @@ | ||
const createServer = require('pico-static-server'); | ||
const createServer = require('./../index.js'); | ||
const staticServer = createServer({ | ||
defaultFile: 'defaultfile.html', // defaults to 'index.html' | ||
staticPath: __dirname + '/static', // defaults to './' | ||
port: 8080, // defaults to 8080 | ||
protocol: 'https', // defaults to 'http' | ||
defaultFile: 'defaultfile.html', // defaults to 'index.html' | ||
staticPath: __dirname + '/static', // defaults to './' | ||
port: 8080, // defaults to 8080 | ||
protocol: 'https', // defaults to 'http' | ||
cert: __dirname + '/localhost.crt', | ||
@@ -9,0 +9,0 @@ key: __dirname + '/localhost.key', |
35
index.js
@@ -62,3 +62,3 @@ const http = require('http'); | ||
* | ||
* @param {Object} res | ||
* @param {Object} response | ||
* @param {number} code | ||
@@ -68,10 +68,10 @@ * @param {Object} headers | ||
*/ | ||
const respond = (res, code, headers, data) => { | ||
res.writeHead(code, headers, http.STATUS_CODES[code]); | ||
const respond = (response, code, headers, data) => { | ||
response.writeHead(code, headers, http.STATUS_CODES[code]); | ||
if (typeof data !== 'undefined') { | ||
res.write(data); | ||
response.write(data); | ||
} | ||
res.end(); | ||
response.end(); | ||
}; | ||
@@ -82,3 +82,3 @@ | ||
* | ||
* @param url | ||
* @param {string} url | ||
* @returns {string} | ||
@@ -91,3 +91,3 @@ */ | ||
* | ||
* @param url | ||
* @param {string} url | ||
* @returns {boolean} | ||
@@ -106,15 +106,14 @@ */ | ||
const responseHandler = (req, res) => { | ||
if (req.method === 'OPTIONS') { | ||
respond(res, 200, UNKNOWN_METHOD_RESPONSE_HEADERS); | ||
const responseHandler = (request, response) => { | ||
if (request.method === 'OPTIONS') { | ||
respond(response, 200, UNKNOWN_METHOD_RESPONSE_HEADERS); | ||
return; | ||
} | ||
if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
respond(res, 405, UNKNOWN_METHOD_RESPONSE_HEADERS); | ||
if (request.method !== 'GET' && request.method !== 'HEAD') { | ||
respond(response, 405, UNKNOWN_METHOD_RESPONSE_HEADERS); | ||
return; | ||
} | ||
const parsedUrl = url.parse(req.url); | ||
let requestPath = path.join(options.staticPath, parsedUrl.pathname); | ||
let requestPath = path.join(options.staticPath, path.normalize(url.parse(request.url).pathname)); | ||
@@ -129,8 +128,8 @@ if (fs.existsSync(requestPath)) { | ||
if (data instanceof Error) { | ||
respond(res, 500, { 'Content-Length': 0 }); | ||
respond(response, 500, { 'Content-Length': 0 }); | ||
} else { | ||
respond(res, 200, { 'Content-type': getMimeType(requestPath), 'Content-length': data.length }, data); | ||
respond(response, 200, { 'Content-type': getMimeType(requestPath), 'Content-length': data.length }, data); | ||
} | ||
} else { | ||
respond(res, 404, { 'Content-Length': 0 }); | ||
respond(response, 404, { 'Content-Length': 0 }); | ||
} | ||
@@ -145,3 +144,3 @@ } | ||
return serverHanhttps.createServer({ | ||
return https.createServer({ | ||
cert: fs.readFileSync(options.cert), | ||
@@ -148,0 +147,0 @@ key: fs.readFileSync(options.key), |
{ | ||
"name": "pico-static-server", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Small yet fully functional Node.js static files server with zero dependencies with HTTPS support", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Pico-static-server | ||
Tiny yet fully functional Node.js static files server with zero dependencies and **HTTPS** support. | ||
Tiny yet fully functional Node.js static files server with zero dependencies and *HTTPS* support. | ||
@@ -19,6 +19,3 @@ ### Install | ||
**HTTPS** example requires you to generate SSL cerificates first: | ||
```bash | ||
cd ./examples | ||
``` | ||
*HTTPS* example requires you to generate SSL cerificates first: | ||
Generate 2048-bit RSA private key and remove the password from generated key | ||
@@ -55,3 +52,3 @@ ```bash | ||
``` | ||
or even HTTPS one: | ||
or even *HTTPS* one: | ||
```javascript | ||
@@ -62,7 +59,7 @@ const createServer = require('pico-static-server'); | ||
defaultFile: 'index.html', // defaults to 'index.html' | ||
staticPath: './static', // defaults to './' | ||
staticPath: __dirname + '/static', // defaults to './' | ||
port: 8080, // defaults to 8080 | ||
protocol: 'https', // defaults to 'http' | ||
cert: __dirname + '/localhost.crt', | ||
key: __dirname + 'localhost.key', | ||
key: __dirname + '/localhost.key', | ||
}); | ||
@@ -69,0 +66,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
82625
139
68