Made page gathering dynamic, added favicon, included css, worked on some content, created first bash page. Still very much in-progress but the framework is pretty much done. Needs more CSS and content.
This commit is contained in:
parent
8cfe6e43e2
commit
2e5ef4391a
104
main.js
104
main.js
@ -1,76 +1,98 @@
|
||||
#!/usr/bin/node
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
2022-09-14 Mockup of what a web server may look like.
|
||||
Should serve very quick since it's all from scratch, nothing to load like WordPress.
|
||||
May even skip out on things like
|
||||
2022-09-14 Hyperling
|
||||
Coding my own website rather than using WordPress or anything bloaty.
|
||||
*/
|
||||
|
||||
const app_name = "www.example.com";
|
||||
//// Libraries ////
|
||||
|
||||
let express = require('express');
|
||||
let app = express();
|
||||
|
||||
const execSync = require('child_process').execSync;
|
||||
|
||||
let pages = {};
|
||||
pages.home = require('./pages/home.js');
|
||||
//pages.notice = require('./pages/notice.js');
|
||||
const fs = require('fs');
|
||||
|
||||
let pages_php = {};
|
||||
pages.home = './pages/home.php';
|
||||
//pages.notice = './pages/notice.php';
|
||||
//// Global Variables ////
|
||||
|
||||
// Even better, look through ./pages/ for *.php or *.js and add them to the array!
|
||||
const DEBUG = false;
|
||||
|
||||
const app_name = "hyperling.com";
|
||||
|
||||
let pages = [];
|
||||
const pages_dir = "./pages/";
|
||||
const file_types = ["php", "sh"];
|
||||
|
||||
let ports = [];
|
||||
ports.push(8080);
|
||||
|
||||
async function main() {
|
||||
console.log("Starting Main");
|
||||
//// Functions ////
|
||||
|
||||
async function main() {
|
||||
console.log("...Starting Main...");
|
||||
|
||||
console.log("Set app to return HTML documents.");
|
||||
app.use(function (req, res, next) {
|
||||
res.contentType('text/html');
|
||||
next();
|
||||
});
|
||||
|
||||
console.log("Adding Routes");
|
||||
/* Loop through all file in the pages subdirectory and add the allowed
|
||||
// file types into the pages array for automatic router creation.
|
||||
*/
|
||||
console.log("...Starting Main...");
|
||||
let ls = await fs.promises.readdir(pages_dir);
|
||||
if (DEBUG) console.log("DEBUG: Results of ls, ", ls);
|
||||
for (let file of ls) {
|
||||
let file_test = file.split(".");
|
||||
let file_name = file_test[0];
|
||||
let file_type = file_test[file_test.length - 1];
|
||||
if (file_types.includes(file_type)) {
|
||||
if (DEBUG) console.log("DEBUG: Hooray!", file, "is being added.");
|
||||
pages[file_name] = pages_dir + file;
|
||||
console.log(" * Added page", file);
|
||||
} else {
|
||||
if (DEBUG) console.log("DEBUG: ", file, "is not an approved type, skipping.");
|
||||
}
|
||||
}
|
||||
console.log(" * Pages loaded: ", pages);
|
||||
//return; // Stop execution FORTESTING
|
||||
|
||||
console.log("...Adding Routes...");
|
||||
let router = express.Router();
|
||||
/* MANUAL METHOD, SPECIFY EVERY PATH+FILE
|
||||
router.get('/', function (req, res) {
|
||||
console.log("Fetching");
|
||||
require('lib/home.js'); // one way, maybe?
|
||||
});
|
||||
router.get('/notice', function (req, res) {
|
||||
pages.notice(req, res); // another way?
|
||||
});
|
||||
*/
|
||||
/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY
|
||||
for page in pages { // FORTESTING pseudocode
|
||||
router.get("/" + page.key, function (req,res) {
|
||||
page.value(req, res);
|
||||
|
||||
/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF PHP scripts
|
||||
// Creates routes with the URL of the key and location of the value.
|
||||
*/
|
||||
for (let key in pages) {
|
||||
console.log(" * Creating router for", key);
|
||||
router.get("/" + key, function (req,res) {
|
||||
console.log(key, "fulfilling request to", req.socket.remoteAddress, "asking for", req.url)
|
||||
res.send(execSync(pages[key]));
|
||||
});
|
||||
}
|
||||
*/
|
||||
/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF PHP scripts
|
||||
for page in pages { // FORTESTING pseudocode
|
||||
router.get("/" + page.key, function (req,res) {
|
||||
res.send(system("php page.value"));
|
||||
});
|
||||
}
|
||||
*/
|
||||
// Test (Also a decent catch-all to Home!)
|
||||
|
||||
// Provide css.
|
||||
router.get('/main.css', function (req, res) {
|
||||
console.log("css being provided to", req.socket.remoteAddress)
|
||||
let html = execSync("cat ./pages/main.css");
|
||||
res.send(html);
|
||||
});
|
||||
|
||||
// Originally a test, now a catch-all redirection to Home!
|
||||
router.get('/*', function (req, res) {
|
||||
// WARNING: These are huge so only look when you need to.
|
||||
//console.log(req);
|
||||
//console.log(res);
|
||||
console.log(req.socket.remoteAddress, "asked for", req.url)
|
||||
let html = execSync("php ./pages/home.php");
|
||||
console.log("*wildcard* replying to", req.socket.remoteAddress, "asking for", req.url)
|
||||
let html = execSync("./pages/home.php");
|
||||
res.send(html);
|
||||
});
|
||||
|
||||
app.use('', router);
|
||||
|
||||
console.log("Adding Ports");
|
||||
console.log("...Adding Ports...");
|
||||
ports.forEach(port => {
|
||||
app.listen(port);
|
||||
console.log(" * Now listening on port " + port + ".");
|
||||
@ -78,4 +100,6 @@ async function main() {
|
||||
console.log("Done! Now we wait...");
|
||||
}
|
||||
|
||||
//// Program Execution ////
|
||||
|
||||
main();
|
||||
|
24
pages/about.php
Normal file → Executable file
24
pages/about.php
Normal file → Executable file
@ -1,2 +1,26 @@
|
||||
#!/usr/bin/php
|
||||
|
||||
<?php
|
||||
include "helpers/body_open.php";
|
||||
?>
|
||||
|
||||
<h1>Curious About Me?</h1>
|
||||
<p>
|
||||
TBD
|
||||
</p>
|
||||
|
||||
<?php
|
||||
include "helpers/section_open.php";
|
||||
include "subpages/about/whoami.php";
|
||||
include "helpers/section_close.php";
|
||||
|
||||
include "helpers/section_open.php";
|
||||
include "subpages/about/stance.php";
|
||||
include "helpers/section_close.php";
|
||||
|
||||
include "helpers/section_open.php";
|
||||
include "subpages/about/notice.php";
|
||||
include "helpers/section_close.php";
|
||||
|
||||
include "helpers/body_close.php";
|
||||
?>
|
||||
|
1
pages/helpers/advisory.php
Executable file
1
pages/helpers/advisory.php
Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
3
pages/helpers/body_close.php
Normal file → Executable file
3
pages/helpers/body_close.php
Normal file → Executable file
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
include "footer.php"
|
||||
?>
|
||||
|
9
pages/helpers/body_open.php
Normal file → Executable file
9
pages/helpers/body_open.php
Normal file → Executable file
@ -1,12 +1,11 @@
|
||||
|
||||
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
include "header.php"
|
||||
include "header.php";
|
||||
?>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
include "menu.php"
|
||||
include "menu.php";
|
||||
include "advisory.php";
|
||||
?>
|
||||
|
||||
|
9
pages/helpers/footer.php
Normal file → Executable file
9
pages/helpers/footer.php
Normal file → Executable file
@ -1,3 +1,6 @@
|
||||
|
||||
<h6> Copyright $year </h6>
|
||||
|
||||
#!/usr/bin/php
|
||||
<h6>
|
||||
<a href="https://github.com/Hyperling/www/blob/main/LICENSE" target="_blank">
|
||||
Copyright <?php echo date("Y"); ?>
|
||||
</a>
|
||||
</h6>
|
||||
|
@ -1 +0,0 @@
|
||||
DELETEME
|
15
pages/helpers/header.php
Normal file → Executable file
15
pages/helpers/header.php
Normal file → Executable file
@ -1,7 +1,16 @@
|
||||
|
||||
|
||||
#!/usr/bin/php
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hyperling</title>
|
||||
<link rel="icon" sizes="32x32"
|
||||
href="https://www.hyperling.com/wp-content/uploads/2020/09/favicon.ico"
|
||||
/>
|
||||
<link rel="icon" sizes="192x192"
|
||||
href="https://www.hyperling.com/wp-content/uploads/2020/09/favicon.ico"
|
||||
/>
|
||||
<!--<link rel="stylesheet" href="/main.css">-->
|
||||
<style>
|
||||
<?php include "main.css"; ?>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -40,3 +40,18 @@
|
||||
clear: both;
|
||||
display: table;
|
||||
}
|
||||
|
||||
/* MyStuff ***/
|
||||
/** Dark Theme **/
|
||||
body {
|
||||
background-color: #333333;
|
||||
}
|
||||
* {
|
||||
color: #CCCCCC;
|
||||
}
|
||||
a {
|
||||
color: #FF9900
|
||||
}
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
color: #6633FF
|
||||
}
|
3
pages/helpers/menu.php
Normal file → Executable file
3
pages/helpers/menu.php
Normal file → Executable file
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
#!/usr/bin/php
|
||||
<ul>
|
||||
<li><a href="/home/">Home</a></li>
|
||||
<li><a href="/about/">About</a></li>
|
||||
|
1
pages/helpers/section_close.php
Normal file → Executable file
1
pages/helpers/section_close.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
1
pages/helpers/section_open.php
Normal file → Executable file
1
pages/helpers/section_open.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
1
pages/subpages/about/notice.php
Normal file → Executable file
1
pages/subpages/about/notice.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
1
pages/subpages/about/stance.php
Normal file → Executable file
1
pages/subpages/about/stance.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
1
pages/subpages/about/whoami.php
Normal file → Executable file
1
pages/subpages/about/whoami.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
1
pages/subpages/home/apps.php
Normal file → Executable file
1
pages/subpages/home/apps.php
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/php
|
||||
<h2> My Public Programs </h2>
|
||||
|
||||
<h3> Android Apps </h3>
|
||||
|
1
pages/subpages/home/contact.php
Normal file → Executable file
1
pages/subpages/home/contact.php
Normal file → Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/php
|
5
pages/subpages/home/health.php
Normal file → Executable file
5
pages/subpages/home/health.php
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
<h1> My Health Protocol </h1>
|
||||
#!/usr/bin/php
|
||||
<h1> My Health Protocol </h1>
|
||||
|
||||
<!-- URL to MyPriorities.pdf on files.hyperling.com -->
|
||||
<!-- URL to MyPriorities.pdf on files.hyperling.com -->
|
3
pages/subpages/support/donate.php
Normal file → Executable file
3
pages/subpages/support/donate.php
Normal file → Executable file
@ -1 +1,2 @@
|
||||
<!-- How people can support me with currency if they so desire. -->
|
||||
#!/usr/bin/php
|
||||
<!-- How people can support me with currency if they so desire. -->
|
3
pages/subpages/support/gifts.php
Normal file → Executable file
3
pages/subpages/support/gifts.php
Normal file → Executable file
@ -1 +1,2 @@
|
||||
<!-- Gift ideas such as dried fruit, teas, etc. -->
|
||||
#!/usr/bin/php
|
||||
<!-- Gift ideas such as dried fruit, teas, etc. -->
|
4
pages/support.php
Normal file → Executable file
4
pages/support.php
Normal file → Executable file
@ -8,8 +8,8 @@
|
||||
include "helpers/body_open.php";
|
||||
?>
|
||||
|
||||
<h1>Support<h1>
|
||||
<p>
|
||||
<h1>Support</h1>
|
||||
<p>
|
||||
While I do not ask for anything, and prefer to take care of myself,
|
||||
I acknowledge that some people enjoy gift giving and would like to
|
||||
help me out. Below are my preferred ways that this be done.
|
||||
|
31
pages/test.sh
Executable file
31
pages/test.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Move to the directory that this file is in.
|
||||
cd `dirname $0`
|
||||
|
||||
# Create the necessary HTML components for a web page.
|
||||
./helpers/body_open.php
|
||||
echo -e "\t\t<h1>This is a web page written in BASH!!!</h1>"
|
||||
cat << EOF
|
||||
<p>
|
||||
Look at all the fancy things we can do!
|
||||
</p>
|
||||
<h2>Current Time</h2>
|
||||
<p>
|
||||
We can use the date command to spit out the time!
|
||||
</p>
|
||||
<p>
|
||||
`date`
|
||||
</p>
|
||||
EOF
|
||||
|
||||
# Create a subsection
|
||||
./helpers/section_open.php
|
||||
echo -e "\t\t<h2>Server Neofetch</h2>"
|
||||
echo -e "\t\t<p>"
|
||||
neofetch --stdout
|
||||
echo -e "\t\t</p>"
|
||||
./helpers/section_close.php
|
||||
|
||||
# Finish the web page
|
||||
./helpers/body_close.php
|
16
run.sh
16
run.sh
@ -2,13 +2,27 @@
|
||||
# 2022-09-14 Hyperling
|
||||
# Ensure dependencies are met and start the webserver.
|
||||
|
||||
# Ensure we are executing from this file's directory.
|
||||
cd `dirname $0`
|
||||
|
||||
### Can docker-compose do this rather than running a sh file on the host OS?
|
||||
# Look at Dockerfile-ADD for doing git clones into a docker environment.
|
||||
# Out of scope for this project, this project is just the site.
|
||||
# Out of scope for this project, this project is just the site, leave for now.
|
||||
if [[ ! `which php` || ! `which node`|| ! `which npm` ]]; then
|
||||
sudo apt install -y php-fpm nodejs npm
|
||||
fi
|
||||
|
||||
# Fix any file permissions
|
||||
# Directories and allowed page types are executable, others are not.
|
||||
find ./pages/ | while read file; do
|
||||
if [[ $file == *".php" || $file == *".sh" || -d $file ]]; then
|
||||
mode=755
|
||||
else
|
||||
mode=644
|
||||
fi
|
||||
chmod -c $mode $file
|
||||
done
|
||||
|
||||
npm install
|
||||
|
||||
./main.js
|
||||
|
Loading…
x
Reference in New Issue
Block a user