Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pico-static-server

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pico-static-server - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

2

examples/pico-http-server.js

@@ -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',

@@ -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 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc