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

grandjs

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grandjs - npm Package Compare versions

Comparing version 1.3.5 to 1.3.6

169

lib/Grand.js

@@ -25,2 +25,3 @@ /*

const cors = require("cors");
const Util = require("util");
// end dependencies

@@ -67,3 +68,2 @@ //define a global variable

this._resolveRoutesWithBase = () => {
// console.log(this.base)
this.getRouters.forEach((obj) => {

@@ -97,3 +97,2 @@ obj.url = path.join(this.base, obj.url);

let allMiddleWares = [corsMiddleWare, ...matchedURL.middleWares];
// console.log(allMiddleWares);
return {

@@ -103,3 +102,3 @@ allMiddleWares

}
this.errorPage = this.errorPage = self.errorPage;
this.errorPage = this.errorPage || self.errorPage;
this.options = options || {};

@@ -117,11 +116,9 @@ this._setBase();

return cors(corsObject)(req, res, next);
// let cors = new Cors(corsObject);
// return cors.init(req, res, next);
// return cors(this.cors, req, res, next);
}
this.staticFolder = this.options.staticFolder || this.staticFolder;
this.bindStaticFolder = this.options.bindStaticFolder || this.bindStaticFolder;
// output warrning
console.warn("Grandjs Routers not will be working with just instantiating the router, you need to call `build()` method after instantiating the router to make it works")
}
build() {
// console.log(self.staticFolder)
this.id = Math.random()

@@ -144,36 +141,38 @@ .toString(36)

}
serveAssets(req, res, next) {
let staticFolder = this.bindStaticFolder || this.staticFolder;
if(staticFolder) {
var sourceFolder = path.resolve("/", staticFolder);
var mimeTypes = config.mimeTypes
var dirName = path.join("", `${sourceFolder}`);
// if (pathname.startsWith(sourceFolder)) {
// pathname = pathname.split(sourceFolder)[1];
// }
let fileSource;
if(this.bindStaticFolder) {
let regex = new RegExp(this.staticFolder, "gi");
let pathname = req.pathname.replace(regex, "");
fileSource = path.join(sourceFolder, pathname);
async serveAssets(req, res, next) {
try {
let staticFolder = this.bindStaticFolder || this.staticFolder;
if(staticFolder) {
var sourceFolder = path.resolve("/", staticFolder);
var mimeTypes = config.mimeTypes
var dirName = path.join("", `${sourceFolder}`);
let fileSource;
if(this.bindStaticFolder) {
let regex = new RegExp(this.staticFolder, "gi");
let pathname = req.pathname.replace(regex, "");
fileSource = path.join(sourceFolder, pathname);
} else {
fileSource = path.join(process.cwd(), req.pathname);
}
// var existFile = fs.existsSync(fileSource);
let promisifiedState = Util.promisify(fs.lstat);
let fileState = (await promisifiedState(fileSource));
if (fileState.isFile()) {
var fileStream = fs.createReadStream(fileSource);
var headers = {
"Content-Type": mimeTypes[path.extname(req.pathname)] || 'application/octet-stream',
// 'Cache-Control': `public, max-age=${cacheControl || 'no-cache'}`,
'Content-Length': fileState.size
};
res.writeHead(200, headers);
return fileStream.pipe(res);
} else {
res.statusCode = 404;
return this.errorPage(req, res);
}
} else {
fileSource = path.join(process.cwd(), req.pathname);
}
var existFile = fs.existsSync(fileSource);
if (existFile) {
var fileStream = fs.createReadStream(fileSource);
let fileState = fs.statSync(fileSource);
var headers = {
"Content-Type": mimeTypes[path.extname(req.pathname)] || 'application/octet-stream',
// 'Cache-Control': `public, max-age=${cacheControl || 'no-cache'}`,
'Content-Length': fileState.size
};
res.writeHead(200, headers);
return fileStream.pipe(res);
} else {
res.statusCode = 404;
return this.errorPage(req, res);
}
} else {
res.statusCode = 404;
} catch(err) {
return this.errorPage(req, res);

@@ -187,3 +186,2 @@ }

if (this.staticFolder) {
// console.log(this.staticFolder)
this.getRouters.unshift({

@@ -233,3 +231,2 @@ url: `/${this.staticFolder}/*`,

this._pushGlobalMiddleWares(newClass.deleteRouters, newClass.globalMiddleWares, newClass.cors);
// console.log(newClass.base)
if(this.base !== newClass.base) {

@@ -319,4 +316,2 @@ newClass._resolveRoutesWithBase()

let matchedURL = getRouters.find(router => {
// console.log("router value", router.value)
// console.log("matched re", matchedRe)
return router.value == matchedRe;

@@ -328,7 +323,5 @@ });

let allMiddleWares = corsSetting.allMiddleWares;
// console.log(allMiddleWares);
if (matchedURL.method == "get") {
res.statusCode = 200;
if (allMiddleWares.length > 0) {
// console.log(matchedURL.middleWares)
var nexted = 0;

@@ -353,15 +346,9 @@ allMiddleWares[0](req, res, next);

} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}
} else {
// this.serveFiles(() => {
// res.statusCode = 404;
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
// });

@@ -418,3 +405,2 @@ }

let allMiddleWares = corsSetting.allMiddleWares;
// console.log(JSON.stringify({mid: allMiddleWares}))
if (

@@ -430,12 +416,6 @@ matchedURL.method.toLowerCase() == "post"

} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}
} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}

@@ -501,12 +481,6 @@ } else if (

} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}
} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}

@@ -572,12 +546,6 @@ } else if (

} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}
} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res);
}

@@ -643,10 +611,6 @@ } else if (

} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}
} else {
return this.errorPage ?
this.errorPage(req, res) :
self.errorPage(req, res);
return this.errorPage(req, res)
}

@@ -838,3 +802,2 @@ }

req.url = url;
// console.log()
req.path = url.path;

@@ -940,22 +903,22 @@ req.href = url.href;

} else {
let ur = config.extenstions.find(
ext => path.extname(pathname) == ext
);
if (ur) {
// return helpers
// .staticFiles(
// req,
// res,
// req.pathname,
// self.staticFolder,
// self.cacheControl
// )
// .catch(src => {
// // res.writeHead(404);
// self.errorPage(req, res);
// });
} else {
res.writeHead(404);
self.errorPage(req, res);
}
// let ur = config.extenstions.find(
// ext => path.extname(pathname) == ext
// );
// if (ur) {
// // return helpers
// // .staticFiles(
// // req,
// // res,
// // req.pathname,
// // self.staticFolder,
// // self.cacheControl
// // )
// // .catch(src => {
// // // res.writeHead(404);
// // self.errorPage(req, res);
// // });
// } else {
// res.writeHead(404);
this.errorPage(req, res);
// }
}

@@ -962,0 +925,0 @@ }

{
"name": "grandjs",
"version": "1.3.5",
"version": "1.3.6",
"description": "A backend framework for solid web apps based on node.js",

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

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