Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
-
  • Loading branch information
suiGn committed Mar 13, 2024
1 parent 3a91040 commit f668495
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 102 deletions.
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/

// Log the successful loading of NetGet
console.log("NetGet Loaded Successfully.");
/**
* Gateway class for handling domain-based routing and server initialization.
* @see Gateway
*/
export { default as Gateway } from './src/Gateway.js';
import NetGet from './src/netget.js';
console.log("NetGet Loaded.");
export default NetGet;
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.31",
"version": "2.3.33",
"description": "Rette Adepto/ Recibido Directamente.",
"type": "module",
"main": "index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class Gateway {
* Initializes the server setup including static file serving, view engine setup, and domain routing.
*/
async initialize() {
// Calculate the base directory for the gateway, assuming the gateway class is in 'src'
const baseDir = path.dirname(fileURLToPath(import.meta.url));
const baseDir = path.dirname(fileURLToPath(import.meta.url)); // Calculate the base directory for the gateway, assuming the gateway class is in 'src'
this.app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies (as sent by HTML forms)
this.app.use(express.json()); // Parse JSON bodies (as sent by API clients)
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'));
Expand Down
25 changes: 10 additions & 15 deletions src/config/domains.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
{
"name": "DefaultDomains",
"name": "DefaultDomains",
"domains": {
"cleaker.me": {"handler": "cleakerHandler", "state": "Active"},
"neurons.me": {"handler": "neuronsHandler", "state": "Active"},
"mlearning.me": {"handler": "mlearningHandler", "state": "Maintenance"}
},
"domains2": {
"cleaker.me": "cleakerHandler",
"neurons.me": "neuronsHandler",
"mlearning.me": "mlearningHandler",
"mlearning.com": "mlearningHandler",
"mlearning.studio": "mlearningHandler",
"mdrn.me": "mdrnHandler",
"monadlisa.me": "monadlisaHandler",
"monadlisa.com": "monadlisaHandler",
"netget.me": "netgetHandler",
"orgboat.me": "orgboatHandler"
}
"mlearning.me": {"handler": "mlearningHandler", "state": "Maintenance"},
"mlearning.com": {"handler": "mlearningHandler", "state": "Active"},
"mlearning.studio": {"handler": "mlearningHandler", "state": "Active"},
"mdrn.me": {"handler": "mdrnHandler", "state": "Active"},
"monadlisa.me": {"handler": "monadlisaHandler", "state": "Active"},
"monadlisa.com": {"handler": "monadlisaHandler", "state": "Active"},
"netget.me": {"handler": "netgetHandler", "state": "Active"},
"orgboat.me": {"handler": "orgboatHandler", "state": "Active"}
}
}
148 changes: 80 additions & 68 deletions src/ejsApp/views/domainList.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,111 +3,123 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Domain Configuration List</title>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<title>Domain Configuration - Interactive View</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Press Start 2P', cursive;
background-color: #01161d;
color: #00ff00;
font-family: 'Roboto', sans-serif;
background-color: #f4f4f4;
color: #333;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.container {
max-width: 600px; /* Adjust based on your preference */
max-width: 800px;
width: 100%;
padding: 20px;
background-color: #ffffff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
.domain-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border-bottom: 1px solid #eaeaea;
}
table, th, td {
border: 1px solid #005500;
.domain-name, .handler-name {
flex-basis: 40%;
}
th, td {
padding: 8px; /* Reduced padding */
text-align: left;
font-size: 0.8rem; /* Smaller font size */
.state-indicator {
height: 15px;
width: 15px;
border-radius: 50%;
display: inline-block;
}
th {
background-color: #003300;
color: #00ff00;
.active {
background-color: #4CAF50;
}
tr:nth-child(even) {
background-color: #001100;
.inactive {
background-color: #f44336;
}
h1 {
color: #00ff00;
text-align: center;
font-size: 1.2rem; /* Adjusted for compactness */
.line {
border-top: 2px dotted #ccc;
flex-grow: 1;
margin: 0 10px;
}
.action-button {
font-family: 'Press Start 2P', cursive;
background-color: #333;
background-color: #008CBA;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 20px auto;
font-size: 14px;
margin: 10px;
cursor: pointer;
}
@media (max-width: 768px) {
h1 {
font-size: 1rem;
}
th, td {
font-size: 0.7rem; /* Even smaller font size for mobile */
}
}
</style>
</head>
<body>
<div class="container">
<h1>Domain Configuration List</h1>
<h1>Domain Configuration</h1>
<% for(const domain in domains) { %>
<div class="domain-item">
<span class="domain-name" contenteditable="false"><%= domain %></span>
<div class="line"></div>
<span class="handler-name" contenteditable="true"><%= domains[domain].handler %></span>
<span class="state-indicator <%= domains[domain].state == 'Active' ? 'active' : 'inactive' %>" onclick="toggleState(this)"></span>
<button onclick="editDomain('<%= domain %>')" class="action-button">Edit</button>
<button onclick="deleteDomain('<%= domain %>')" class="action-button">Delete</button>
</div>
<% } %>

<button class="action-button">Add Domain</button>
<a href="/" class="action-button">Go Back</a>
</div>

<table>
<tr>
<th>Domain Name</th>
<th>Handler</th>
<th>State</th>
</tr>
<% for(const domain in domains) { %>
<tr>
<td><%= domain %></td>
<td><%= domains[domain].handler %></td>
<td><%= domains[domain].state %></td>
</tr>
<% } %>
</table>

<!-- Add Domain Form -->
<div id="addDomainForm" style="display: none;">
<!-- Add Domain Form and JavaScript can be retained from previous versions -->
<!-- Toggleable Add Domain Form -->
<div id="addDomainForm" style="display: none;">
<h2>Add New Domain</h2>
<form action="/addDomain" method="post">
<label for="domain">Domain Name:</label>
<input type="text" id="domain" name="domain"><br><br>
<label for="handler">Handler:</label>
<input type="text" id="handler" name="handler"><br><br>
<input type="submit" value="Submit">
<form id="addDomain" action="/addDomain" method="post">
<input type="text" id="newDomain" name="domain" placeholder="Domain Name" required>
<input type="text" id="newHandler" name="handler" placeholder="Handler" required>
<select name="state" id="newState">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
<button type="submit" class="action-button">Add Domain</button>
</form>
</div>

<button class="action-button" onclick="toggleForm()">Add Domain</button>
<script>
document.querySelector('.action-button').addEventListener('click', () => {
// Toggle the form visibility
const form = document.getElementById('addDomainForm');
form.style.display = form.style.display === 'none' ? 'block' : 'none';
});
</script>
function editDomain(domain) {
// Logic to handle domain editing (AJAX request to update the backend)
}
function deleteDomain(domain) {
// Logic to handle domain deletion (AJAX request to update the backend)
}
function toggleState(element) {
// Toggle state visualization and update backend
if (element.classList.contains('active')) {
element.classList.remove('active');
element.classList.add('inactive');
} else {
element.classList.remove('inactive');
element.classList.add('active');
}
}
</script>



</body>
</html>
9 changes: 9 additions & 0 deletions src/ejsApp/views/partials/addDomain.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form action="/addDomain" method="post">
<input type="text" name="domain" placeholder="Domain Name" required>
<input type="text" name="handler" placeholder="Handler" required>
<select name="state">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
<button type="submit" class="action-button">Add Domain</button>
</form>
24 changes: 24 additions & 0 deletions src/netget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// src/netget.js
import Gateway from './gateway.js';
class NetGet {
constructor() {
// Initialization code, if necessary
}

static loadDomainConfig(domainConfigPath) {
try {
const data = fs.readFileSync(domainConfigPath, 'utf8');
const domainConfig = JSON.parse(data);
console.log('Loaded Domain Configuration:', domainConfig);
// Additional processing or setup based on the domainConfig
return domainConfig;
} catch (err) {
console.error('Error loading domain configuration:', err);
return null; // Or throw an error, depending on your preference
}
}

// NetGet related functionalities
}
NetGet.Gateway = Gateway;
export default NetGet;
15 changes: 5 additions & 10 deletions src/routes/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';

import fs from 'fs/promises'; // Ensure fs is imported for file operations
import { loadDomainConfig } from '../config/domainConfigUtils.js'; // Adjust the import path as necessary

Expand All @@ -23,18 +24,12 @@ export default function initializeRoutes(domainsConfigPath) {

// Endpoint to add a new domain
router.post('/addDomain', async (req, res) => {
const { domain, handler } = req.body;
try {
const domainsConfig = await loadDomainConfig(domainsConfigPath);
domainsConfig.domains[domain] = handler; // Add the new domain
await fs.writeFile(domainsConfigPath, JSON.stringify(domainsConfig, null, 2)); // Ensure path is correct
res.redirect('/domainList'); // Redirect back to the domain list
} catch (err) {
console.error('Failed to add domain:', err);
res.status(500).send('Error adding domain');
}
console.log(req.body); // Check to see if the data is coming through
const { domain, handler, state } = req.body;
// Rest of your logic...
});


// Define other routes...

return router;
Expand Down

0 comments on commit f668495

Please sign in to comment.