Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
-
  • Loading branch information
suiGn committed Mar 15, 2024
1 parent a887d8c commit f001702
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/Gateway.html
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ <h4 class="name" id="listen">
<p class="tag-source">
<a href="src_gateway.js.html" class="button">View Source</a>
<span>
<a href="src_gateway.js.html">src/gateway.js</a>, <a href="src_gateway.js.html#line52">line 52</a>
<a href="src_gateway.js.html">src/gateway.js</a>, <a href="src_gateway.js.html#line65">line 65</a>
</span>
</p>

Expand Down Expand Up @@ -1093,7 +1093,7 @@ <h4 class="name" id="listen">
<p class="tag-source">
<a href="src_gateway.js.html" class="button">View Source</a>
<span>
<a href="src_gateway.js.html">src/gateway.js</a>, <a href="src_gateway.js.html#line52">line 52</a>
<a href="src_gateway.js.html">src/gateway.js</a>, <a href="src_gateway.js.html#line65">line 65</a>
</span>
</p>

Expand Down
4 changes: 2 additions & 2 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ <h1>index.js</h1>
<article>
<pre class="prettyprint source linenums"><code>/**
* Entry point of the application.
* It exports all NetGet tools as default NetGet
* Gateway is a customizable gateway server.
* default exports NetGet
*
* @module index
*/

Expand Down
3 changes: 1 addition & 2 deletions docs/module-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ <h1>index</h1>


<div class="description">Entry point of the application.
It exports all NetGet tools as default NetGet
Gateway is a customizable gateway server.</div>
default exports NetGet</div>



Expand Down
23 changes: 18 additions & 5 deletions docs/src_Gateway.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h1>src/gateway.js</h1>
<pre class="prettyprint source linenums"><code>import express from 'express';
import path from 'path';
import morgan from 'morgan';
import defaultHandler from './handlers/defaultHandler.js';
import defaultRoutes from './handlers/defaultRoutes.js';
import { fileURLToPath } from 'url';

// Determine the base directory for static file serving and view engine setup
Expand All @@ -151,7 +151,7 @@ <h1>src/gateway.js</h1>
*/
constructor({ port = 3432, handlers = {} } = {}) {
this.port = port;
this.handlers = handlers;
this.routes = routes;
this.app = express();
this.initialize().catch(err => console.error('Initialization error:', err));
}
Expand All @@ -165,19 +165,32 @@ <h1>src/gateway.js</h1>
this.app.use(express.static(path.join(baseDir, 'ejsApp', 'public')));
this.app.set('view engine', 'ejs');
this.app.set('views', path.join(baseDir, 'ejsApp', 'views'));

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
/* 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);
});
}

*/
this.app.use((req, res) => {
// Check if handlers object is empty (no handlers defined at all)
const noRoutesDefined = Object.keys(this.handlers).length === 0;
const routes = this.routes[req.hostname] || ((req, res) => defaultRoutes(req, res, noHRoutesDefined));
handler(req, res);
});
}
/**
* Starts the gateway, making it listen on the configured port.
*/
Expand Down
204 changes: 204 additions & 0 deletions docs/src_routes_defaultRoutes.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@


<!DOCTYPE html>
<html lang="en">

<head>
...
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NetGet src/routes/defaultRoutes.js</title>

<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="./build/entry.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
<link type="text/css" rel="stylesheet" href="style.css">
<script async defer src="https://buttons.github.io/buttons.js"></script>


</head>



<body class="layout small-header">
<div id="stickyNavbarOverlay"></div>


<div class="top-nav">
<div class="inner">
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<div class="logo">


<a href="index.html">
<h1 class="navbar-item">NetGet</h1>
</a>

</div>
<div class="menu">

<div class="navigation">
<a
href="index.html"
class="link"
>
Documentation
</a>



<a
class="link user-link "
href="https://suign.github.io/all.this/"
>
All.This
</a>

<a
class="link user-link "
href="https://suign.github.io/"
>
@Source
</a>

<a
class="link user-link "
href="https://github.com/suiGn/netget"
>
Github
</a>

<a
class="link user-link "
href="https://netget.me"
>
netget.me
</a>

<a
class="link user-link "
href="https://www.neurons.me/all-this"
>
What is all.this?
</a>



</div>
</div>
</div>
</div>
<div id="main">
<div
class="sidebar "
id="sidebarNav"
>

<div class="search-wrapper">
<input id="search" type="text" placeholder="Search docs..." class="input">
</div>

<nav>

<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Modules</h3><ul><li><a href="module-index.html">index</a></li></ul><h3>Classes</h3><ul><li><a href="Gateway.html">Gateway</a></li></ul><h3>Global</h3><ul><li><a href="global.html#testGateway">testGateway</a></li></ul></div>

</nav>
</div>
<div class="core" id="main-content-wrapper">
<div class="content">
<header class="page-title">
<p>Source</p>
<h1>src/routes/defaultRoutes.js</h1>
</header>





<section>
<article>
<pre class="prettyprint source linenums"><code>// ./src/handlers/defaultHandler.js
/**
* Renders a default response when no specific handler is found for a request.
* This function serves as a fallback handler to provide informative feedback to the user or administrator.
* It indicates whether no handlers are defined at all or if a specific handler for the requested domain is missing.
*
* @param {Object} req - The HTTP request object provided by Express.js.
* @param {Object} res - The HTTP response object provided by Express.js.
* @param {boolean} [noRoutessDefined=false] - Indicates whether no handlers have been defined in the gateway.
*/
export default function defaultRoutes(req, res, noRoutesDefined = false) {
let message = " ";
if (noRoutesDefined) {
message += " No Routes have been defined.&lt;br/> To configure your Domain Routes, please refer to Docs: &lt;br/> https://netget.me ";
} else {
message += ` No Route found for ${req.hostname}.&lt;br/> If you are the administrator, please define a route for this domain. &lt;br/> https://netget.me `;
}

const showDomainListLink = !noRoutesDefined;

res.render('index', {
title: "Gateway Initiated!",
message: message,
showDomainListLink: showDomainListLink
});
}
</code></pre>
</article>
</section>




</div>

<footer class="footer">
<div class="content has-text-centered">
<p>
<style>
.center-div {
display: flex;
justify-content: center;
align-items: center;
height: 89px;
}

img {
max-width: 100%;
max-height: 100%;
}
</style>
<div class="center-div">
<img src="https://suign.github.io/neurons.me/neurons_logo.png" alt="Witness our Seal.">
</div>
<a href="http://neurons.me" target="_blank">neurons.me</a>
</p>
</div>
</footer>

</div>
<div id="side-nav" class="side-nav">
</div>
</div>
<script src="scripts/app.min.js"></script>
<script>PR.prettyPrint();</script>
<script src="scripts/linenumber.js"> </script>

<script src="scripts/search.js"> </script>


</body>
</html>
9 changes: 8 additions & 1 deletion docs/tests_test.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ <h1>tests/test.js</h1>
*/
const testGateway = new Gateway({
port: 3000,
domainsConfigPath: './config/domains.json'
routes: {
'example.com': (req, res) => {
res.send('Hello from example.com!');
},
'another.com': (req, res) => {
res.send('Hello from another.com!');
}
}
});

testGateway.listen();</code></pre>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Entry point of the application.
* It exports all NetGet tools as default NetGet
* Gateway is a customizable gateway server.
* default exports NetGet
*
* @module index
*/

Expand Down
2 changes: 1 addition & 1 deletion jsdoc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"include": ["./src/","./src/gateway.js", "./src/netget.js", "./src/handlers/defaultHandler.js", "./src/routes/routes.js", "./index.js", "./tests/"]
"include": ["./src/","./src/gateway.js", "./src/netget.js", "./src/routes/defaultRoutes.js", "./src/routes/routes.js", "./index.js", "./tests/"]
},
"opts": {
"destination": "./docs",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netget",
"version": "2.3.34",
"version": "2.3.35",
"description": "Rette Adepto/ Recibido Directamente.",
"type": "module",
"main": "index.js",
Expand Down
23 changes: 18 additions & 5 deletions src/Gateway.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import path from 'path';
import morgan from 'morgan';
import defaultHandler from './handlers/defaultHandler.js';
import defaultRoutes from './handlers/defaultRoutes.js';
import { fileURLToPath } from 'url';

// Determine the base directory for static file serving and view engine setup
Expand All @@ -19,7 +19,7 @@ class Gateway {
*/
constructor({ port = 3432, handlers = {} } = {}) {
this.port = port;
this.handlers = handlers;
this.routes = routes;
this.app = express();
this.initialize().catch(err => console.error('Initialization error:', err));
}
Expand All @@ -33,19 +33,32 @@ class Gateway {
this.app.use(express.static(path.join(baseDir, 'ejsApp', 'public')));
this.app.set('view engine', 'ejs');
this.app.set('views', path.join(baseDir, 'ejsApp', 'views'));

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
/* 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);
});
}

*/
this.app.use((req, res) => {
// Check if handlers object is empty (no handlers defined at all)
const noRoutesDefined = Object.keys(this.handlers).length === 0;
const routes = this.routes[req.hostname] || ((req, res) => defaultRoutes(req, res, noHRoutesDefined));
handler(req, res);
});
}
/**
* Starts the gateway, making it listen on the configured port.
*/
Expand Down
Loading

0 comments on commit f001702

Please sign in to comment.