Socket
Socket
Sign inDemoInstall

node-tool-utils

Package Overview
Dependencies
40
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# [1.4.0](https://github.com/hubcarl/node-tool-utils/compare/1.3.0...1.4.0) (2019-10-21)
### Features
* set header[Access-Control-Allow-Origin]=* for CORS and auto serv no file ext ([60fc0c7](https://github.com/hubcarl/node-tool-utils/commit/60fc0c7))
# [1.3.0](https://github.com/hubcarl/node-tool-utils/compare/1.2.3...1.3.0) (2019-09-07)

@@ -2,0 +11,0 @@

41

lib/tool.js

@@ -75,11 +75,25 @@ 'use strict';

httpserver.beforeServe = (request, response, body, encoding) => {
['md', 'lock', 'log', 'ts', 'jsx', 'tsx', 'tpl', 'sql'].forEach(ext => {
response.setHeader('Access-Control-Allow-Origin', '*');
// image
httpserver.config.contentType['webp'] = 'image/webp';
httpserver.config.contentType['svg'] = 'image/svg+xml';
// special
httpserver.config.contentType['xml'] = 'application/xml';
// text
const textTypes = ['md', 'lock', 'log', 'ts', 'jsx', 'tsx', 'tpl', 'sql', 'less', 'styl', 'stylus', 'scss'];
textTypes.forEach(ext => {
httpserver.config.contentType[ext] = 'text/plain';
});
'mp4|webm|ogg|mp3|wav|flac|aac|zip|tar|tar.gz|tar.xz|doc|pdf|xls|msi|7z|pkg|ipa|woff|woff2|eot|ttf|otf'.split('|').forEach(v => {
// stream
const streamTypes = 'mp4|webm|ogg|mp3|wav|flac|aac|zip|tar|tar.gz|tar.xz|doc|docx|xls|ppt|pdf|msi|7z|pkg|ipa|woff|woff2|eot|ttf|otf'.split('|');
streamTypes.forEach(v => {
httpserver.config.contentType[v] = 'application/octet-stream';
});
const pathname = request.uri.pathname;
const filepath = path.join(root, pathname.replace(/^\//, ''));
if (response.statusCode === 415) {
const pathname = request.uri.pathname;
const filepath = path.join(root, pathname.replace(/^\//, ''));
if (fs.existsSync(filepath)) {

@@ -98,2 +112,17 @@ if (fs.statSync(filepath).isDirectory()) {

}
} else if (response.statusCode === 404 ) {
// auto match file ext
if (filepath.indexOf('.') === -1) {
const extKeys = Object.keys(httpserver.config.contentType);
const ext = extKeys.find(ext => {
const file = `${filepath}.${ext}`;
return fs.existsSync(file);
});
if (ext) {
response.setHeader('Content-Type', httpserver.config.contentType[ext]);
response.statusCode = 200;
body.value = fs.readFileSync(`${filepath}.${ext}`);
return;
}
}
}

@@ -129,3 +158,3 @@ };

const pathname = file.replace(root, '');
return {
return {
pathname,

@@ -136,3 +165,3 @@ filepath: file,

});
}
}
return [{ filename, pathname, filepath: rootFilePath }];

@@ -139,0 +168,0 @@ }

2

package.json
{
"name": "node-tool-utils",
"version": "1.3.0",
"version": "1.4.0",
"description": "node cross-platform tool library",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc