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

impress

Package Overview
Dependencies
Maintainers
4
Versions
719
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impress - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

14

impress.js

@@ -37,3 +37,3 @@ 'use strict';

const exit = async (message) => {
const exit = async (message, code) => {
if (impress.finalization) return;

@@ -43,3 +43,3 @@ impress.finalization = true;

if (impress.logger && impress.logger.active) await impress.logger.close();
process.exit(1);
process.exit(code);
};

@@ -52,3 +52,3 @@

if (type === 'warning') return;
if (impress.initialization) exit('Can not start Application server');
if (impress.initialization) exit('Can not start Application server', 1);
};

@@ -69,3 +69,3 @@

else app.threads.delete(id);
if (impress.initialization) exit('Can not start Application server');
if (impress.initialization) exit('Can not start Application server', 1);
if (app.threads.size === 0) {

@@ -130,3 +130,3 @@ impress.applications.delete(app.path);

}
if (!valid) exit('Application server configuration is invalid');
if (!valid) exit('Application server configuration is invalid', 1);
};

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

const config = await new Config(configPath, CFG_OPTIONS).catch((error) => {
exit(`Can not read configuration: ${configPath}\n${error.stack}`);
exit(`Can not read configuration: ${configPath}\n${error.stack}`, 1);
});

@@ -203,3 +203,3 @@ await validateConfig(config);

await portsClosed;
exit('Application server stopped');
exit('Application server stopped', 0);
};

@@ -206,0 +206,0 @@

@@ -47,5 +47,7 @@ 'use strict';

for (const folder of folders) {
const key = this.files.get(`/${folder}/key.pem`);
const cert = this.files.get(`/${folder}/cert.pem`);
if (!Buffer.isBuffer(key) || !Buffer.isBuffer(cert)) continue;
const keyFile = this.files.get(`/${folder}/key.pem`);
const certFile = this.files.get(`/${folder}/cert.pem`);
if (!keyFile || !certFile) continue;
const key = keyFile.data;
const cert = certFile.data;
const domains = [];

@@ -59,7 +61,8 @@ try {

}
const creds = node.tls.createSecureContext({ key, cert });
const context = { key, cert, creds };
const options = { key, cert };
const creds = node.tls.createSecureContext(options);
const context = { ...options, creds };
for (const domain of domains) this.domains.set(domain, context);
if (!this.application.server?.httpServer.setSecureContext) continue;
this.application.server.httpServer.setSecureContext({ key, cert });
this.application.server.httpServer.setSecureContext(options);
} catch (error) {

@@ -66,0 +69,0 @@ for (const domain of domains) this.domains.delete(domain);

@@ -9,2 +9,16 @@ 'use strict';

const STATUS_CACHE = new Map();
const status = (code) => {
let file = STATUS_CACHE.get(code);
if (file) return file;
const status = node.http.STATUS_CODES[code] || 'Unknown error';
const data = Buffer.from(`<!DOCTYPE html>
<html><head><title>${code} ${status}</title></head>
<body><h1>${code} ${status}</h1></body></html>`);
file = { data, stat: null, code };
STATUS_CACHE.set(code, file);
return file;
};
class Static extends Place {

@@ -42,9 +56,9 @@ constructor(name, application, options = {}) {

try {
const { size } = await node.fsp.stat(filePath);
const stat = await node.fsp.stat(filePath);
const key = this.getKey(filePath);
if (size > this.maxFileSize) {
this.files.set(key, { size });
if (stat.size > this.maxFileSize) {
this.files.set(key, { data: null, stat });
} else {
const data = await node.fsp.readFile(filePath);
this.files.set(key, data);
this.files.set(key, { data, stat });
}

@@ -56,28 +70,53 @@ } catch {

find(path, code, parent = false) {
let filePath = path;
const root = path === '/';
if (code) {
const fileName = `.${code}.html`;
filePath = node.path.join(filePath, fileName);
const file = this.get(filePath);
if (file) return { data: file.data, stat: null, code };
if (root) return status(code);
} else {
const folder = path.endsWith('/');
if (folder && !parent) filePath = node.path.join(path, 'index.html');
let file = this.get(filePath);
if (file) return { ...file, code: 200 };
filePath = node.path.join(path, '.virtual.html');
file = this.get(filePath);
if (file) return { ...file, code: -1 };
if (root) return this.find(filePath, 404, true);
}
filePath = node.path.dirname(path);
if (filePath !== '/') filePath += '/';
return this.find(filePath, code, true);
}
async serve(url, transport) {
const [urlPath, params] = metarhia.metautil.split(url, '?');
const folder = urlPath.endsWith('/');
const filePath = urlPath + (folder ? 'index.html' : '');
const [filePath] = metarhia.metautil.split(url, '?');
const fileExt = metarhia.metautil.fileExt(filePath);
const data = this.get(filePath);
if (Buffer.isBuffer(data)) return void transport.write(data, 200, fileExt);
if (!folder && this.get(urlPath + '/index.html')) {
const query = params ? '?' + params : '';
return void transport.redirect(urlPath + '/' + query);
let file = this.find(filePath);
if (file.data && file.stat) {
if (file.code === -1) return void transport.write(file.data, 200, 'html');
return void transport.write(file.data, file.code, fileExt);
}
const absPath = node.path.join(this.path, url);
if (absPath.startsWith(this.path)) {
const stat = await node.fsp.stat(absPath).catch(() => null);
if (!stat || !stat.isFile()) return void transport.error(404);
const { size } = stat;
const range = metarhia.metautil.parseRange(transport.req.headers.range);
const { start, end = size - 1 } = range;
if (start >= end || start >= size || end >= size) {
return void transport.error(416);
let { stat } = file;
if (!stat) stat = await node.fsp.stat(absPath).catch(() => null);
if (stat && stat.isFile()) {
const { size } = stat;
const range = metarhia.metautil.parseRange(transport.req.headers.range);
const { start, end = size - 1 } = range;
if (start >= end || start >= size || end >= size) {
file = this.find(filePath, 416);
return void transport.write(file.data, 416, fileExt);
}
const options = { start, end, size };
const readable = node.fs.createReadStream(absPath, options);
return void transport.write(readable, 206, fileExt, options);
}
const options = { start, end, size };
const readable = node.fs.createReadStream(absPath, options);
return void transport.write(readable, 206, fileExt, options);
}
transport.error(404);
if (file.code === -1) return void transport.write(file.data, 200, 'html');
return void transport.write(file.data, 404);
}

@@ -84,0 +123,0 @@ }

{
"name": "impress",
"version": "3.0.4",
"version": "3.0.5",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -65,3 +65,3 @@ "description": "Enterprise application server for Node.js",

"dependencies": {
"metacom": "^3.0.5",
"metacom": "^3.0.6",
"metaconfiguration": "^2.1.11",

@@ -68,0 +68,0 @@ "metalog": "^3.1.12",

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