New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

netget

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netget - npm Package Compare versions

Comparing version 2.3.38 to 2.3.51

src/routes/defaultHandlers.js

6

index.js

@@ -8,5 +8,5 @@ /**

// Log the successful loading of NetGet
import NetGet from './src/netget.js';
console.log("NetGet Loaded.");
export default NetGet;
export { defaultHandler } from './src/routes/defaultHandlers.js';
export default NetGet;
console.log("NetGet Loaded.");
{
"name": "netget",
"version": "2.3.38",
"version": "2.3.51",
"description": "Rette Adepto/ Recibido Directamente.",

@@ -31,2 +31,3 @@ "type": "module",

"dependencies": {
"chalk": "^5.3.0",
"commander": "^12.0.0",

@@ -33,0 +34,0 @@ "morgan": "^1.10.0"

@@ -18,3 +18,2 @@ <img src="https://suign.github.io/assets/imgs/netget.png" alt="netget.me" width="244" height="203">

Install NetGet via npm:
```bash

@@ -26,3 +25,2 @@ npm install netget

Import NetGet in your Node.js application:
```js

@@ -36,3 +34,2 @@ import { Gateway } from 'netget';

Now you can:
```bash

@@ -39,0 +36,0 @@ npm start

@@ -0,1 +1,2 @@

//src/gateway.js
import express from 'express';

@@ -6,23 +7,31 @@ import path from 'path';

import { fileURLToPath } from 'url';
// Determine the base directory for static file serving and view engine setup
import fs from 'fs';
import chalk from 'chalk';
// Determine the base directory for static file serving and view engine setup8
const baseDir = path.dirname(fileURLToPath(import.meta.url));
/**
* Represents a customizable gateway server.
*/
/***********************
* Customizable Gateway.*
***********************/
class Gateway {
/**
/**
* Initializes a new instance of the Gateway class.
* @param {Object} config - The configuration object for the gateway.
* @param {Object} [config.host='localhost'] - The host name on which the gateway will listen.
* @param {number} [config.port=3432] - The port number on which the gateway will listen.
* @param {Object} [config.handlers={}] - An object mapping domains to their respective request handlers.
* @param {Object} [config.routes={}] - An object mapping domains to their respective request handlers.
* @param {string} [config.domainsConfigPath='./config/domains.json'] - The path to the domains configuration file.
*/
constructor({ port = 3432, routes = {} } = {}) {
constructor({
host = process.env.HOST || 'localhost',
port = process.env.NETGET_PORT || 3432,
routes = {},
domainsConfigPath = process.env.DOMAINS_CONFIG_PATH || './config/domains.json'
} = {}) {
this.host = host;
this.port = port;
this.routes = routes;
this.domainsConfigPath = domainsConfigPath;
this.app = express();
this.initialize().catch(err => console.error('Initialization error:', err));
}
/**

@@ -37,27 +46,34 @@ * Initializes the express application with middleware, static file serving, and view engine setup.

this.app.set('views', path.join(baseDir, 'ejsApp', 'views'));
if (!fs.existsSync(this.domainsConfigPath)) {
console.error(chalk.yellow('Domains Configuration File Not Found.',
'\n','Please provide a valid path @ .env Line DOMAINS_CONFIG_PATH=...'));
//process.exit(1); // Exit if the configuration file doesn't exist
}
morgan.token('host', (req) => req.hostname || req.headers['host'] || '-');
this.app.use(morgan(':method :url :status :res[content-length] - :response-time ms - Host: :host'));
/* This middleware checks the request's ::::::::hostname::::::and uses the corresponding handler or the default one.
Hard-coded and Dynamic Domain Handling in the Gateway ,
Define two methods.
1. Static object this.handlers for domains with predefined handlers.
2. Fetch Handler configurations dynamically from a PostgreSQL database v.path.mlisa.me,
for domains that require dynamic content serving, such as browser.pixelgrid.me/html.js.
this.app.use((req, res) => {
// Check if handlers object is empty (no handlers defined at all)
const noHandlersDefined = Object.keys(this.handlers).length === 0;
const handler = this.handlers[req.hostname] || ((req, res) => defaultHandler(req, res, noHandlersDefined));
handler(req, res);
const hostname = req.hostname || req.headers['host'];
let handler = null;
// Iterate over the routes to find a match
Object.keys(this.routes).forEach(pattern => {
if (pattern === hostname) {
// Direct hostname match
handler = this.routes[pattern];
} else if (pattern.startsWith('*.')) {
// Wildcard domain match
const baseDomain = pattern.slice(2);
if (hostname.endsWith(baseDomain) && (hostname.split('.').length === baseDomain.split('.').length + 1)) {
handler = this.routes[pattern];
}
}
});
}
*/
this.app.use((req, res) => {
// Check if handlers object is empty (no handlers defined at all)
const noRoutesDefined = Object.keys(this.routes).length === 0;
const routes = this.routes[req.hostname] || ((req, res) => defaultRoutes(req, res, noRoutesDefined));
routes(req, res);
// Use the found handler or fallback to default
handler = handler || defaultRoutes;
handler(req, res);
});
}

@@ -68,8 +84,7 @@ /**

listen() {
this.app.listen(this.port, () => {
console.log(`Gateway listening at http://localhost:${this.port}`);
this.app.listen(this.port, this.host, () => {
console.log(chalk.green(`Gateway listening at http://${this.host}:${this.port}`));
});
}
}
export default Gateway;

@@ -7,2 +7,8 @@ // src/netget.js

}
Gateway(config) {
// Gateway is now an instance method that returns a new Gateway instance.
const gateway = new Gateway(config);
return gateway;
}

@@ -24,3 +30,2 @@ static loadDomainConfig(domainConfigPath) {

}
NetGet.Gateway = Gateway;
export default NetGet;
export default NetGet;

@@ -1,2 +0,2 @@

// ./src/handlers/defaultHandler.js
// ./src/handlers/defaultRoutes.js
/**

@@ -17,3 +17,3 @@ * Renders a default response when no specific handler is found for a request.

message += ` No Route found for ${req.hostname}.<br/> If you are the administrator, please define a route for this domain. <br/> https://netget.me `;
}
}

@@ -20,0 +20,0 @@ const showDomainListLink = !noRoutesDefined;

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