Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

rece

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

rece - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+1
spec/single.html
<h1>Im Single!</h1>
+1
-0

@@ -15,2 +15,3 @@ const path = require('path'),

this.chain = [];
this.staticFiles = [];

@@ -17,0 +18,0 @@ this.server = http.createServer();

+42
-20

@@ -11,27 +11,49 @@ /*

module.exports = function() {
function processor(req, res, next) {
if(this.route && this.route !== req.path) {
return next();
}
let file = this.path;
if(!this.route) {
file = path.join(this.path,
(req.path === '/' ? './index.html' : req.path));
}
//console.log(file);
const pathPieces = arguments;
fs.access(file, fs.constants.F_OK | fs.constants.R_OK, err => {
if(!err) {
res.setHeader(
'content-type',
CONTENT_TYPES[
path.extname(file).substring(1).toLowerCase()
] || 'text/plain');
return function(req, res, next) {
const file = path.join(
...pathPieces,
(req.path === '/' ? './index.html' : req.path));
fs.createReadStream(file).pipe(res);
fs.access(file, fs.constants.F_OK | fs.constants.R_OK, err => {
if(!err) {
res.setHeader(
'content-type',
CONTENT_TYPES[
path.extname(file).substring(1).toLowerCase()
] || 'text/plain');
next(true);
} else {
next();
}
});
};
module.exports = function(...pathPieces) {
const ext = path.extname(pathPieces[pathPieces.length - 1]);
fs.createReadStream(file).pipe(res);
// If there is no file extension its a static folder
let ctx = {
route: null,
path: path.join(...pathPieces)
};
next(true);
} else {
next();
}
});
}.bind(path);
if(ext) {
ctx = {
route: pathPieces[0],
path: path.join(...pathPieces.slice(1))
};
}
return processor.bind(ctx);
};
{
"name": "rece",
"version": "1.1.0",
"version": "1.2.0",
"description": "Request, Response, Repeat.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -94,5 +94,5 @@ const fs = require('fs'),

expect(srv.chain[1]).toBe(p1);
expect(srv.chain[2]).toBe(p2);
expect(srv.chain[3]).toBe(p3);
expect(srv.chain[2]).toBe(p1);
expect(srv.chain[3]).toBe(p2);
expect(srv.chain[4]).toBe(p3);
});

@@ -138,3 +138,15 @@

srv.serve(__dirname, 'public');
srv.serve('/single/file', __dirname, 'single.html');
it('should be able to serve single files', () => {
return request({
uri: `${urlBase}/single/file`,
resolveWithFullResponse: true
}).then((res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toBe('text/html');
expect(res.body).toBe('<h1>Im Single!</h1>');
});
});
it('should serve html files', () => {

@@ -141,0 +153,0 @@ return request({