From 7648f2f728816e40752747e7d9ffa6dcd1333e1b Mon Sep 17 00:00:00 2001 From: Hyperling Date: Thu, 6 Oct 2022 07:05:46 -0500 Subject: [PATCH] Add my test project up to this point. --- main.js | 81 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +++ pages/body_close.php | 8 +++++ pages/body_open.php | 12 +++++++ pages/footer.php | 3 ++ pages/head.php | 1 + pages/header.php | 7 ++++ pages/home.js | 17 ++++++++++ pages/home.php | 14 ++++++++ pages/main.css | 42 +++++++++++++++++++++++ pages/menu.php | 5 +++ pages/notice.js | 0 run.sh | 17 ++++++++++ test.html | 27 +++++++++++++++ 14 files changed, 239 insertions(+) create mode 100755 main.js create mode 100644 package.json create mode 100644 pages/body_close.php create mode 100644 pages/body_open.php create mode 100644 pages/footer.php create mode 100644 pages/head.php create mode 100644 pages/header.php create mode 100755 pages/home.js create mode 100755 pages/home.php create mode 100644 pages/main.css create mode 100644 pages/menu.php create mode 100755 pages/notice.js create mode 100755 run.sh create mode 100644 test.html diff --git a/main.js b/main.js new file mode 100755 index 0000000..492ec4e --- /dev/null +++ b/main.js @@ -0,0 +1,81 @@ +#!/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 +*/ + +const app_name = "www.example.com"; +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'); + +let pages_php = {}; +pages.home = './pages/home.php'; +//pages.notice = './pages/notice.php'; + +// Even better, look through ./pages/ for *.php or *.js and add them to the array! + +let ports = []; +ports.push(8080); + +async function main() { + console.log("Starting Main"); + + app.use(function (req, res, next) { + res.contentType('text/html'); + next(); + }); + + 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 + 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!) + router.get('/*', function (req, res) { + //console.log(req); + //console.log(res); + console.log(req.socket.remoteAddress, "asked for", req.url) + let html = execSync("php ./pages/home.php"); + res.send(html); + }); + + app.use('', router); + + console.log("Adding Ports"); + ports.forEach(port => { + app.listen(port); + console.log(" * Now listening on port " + port + "."); + }); + console.log("Done! Now we wait..."); +} + +main(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..0b225ee --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "express": "^4.18.1" + } +} diff --git a/pages/body_close.php b/pages/body_close.php new file mode 100644 index 0000000..17a4126 --- /dev/null +++ b/pages/body_close.php @@ -0,0 +1,8 @@ +#!/bin/php + + + + + diff --git a/pages/body_open.php b/pages/body_open.php new file mode 100644 index 0000000..5c97c78 --- /dev/null +++ b/pages/body_open.php @@ -0,0 +1,12 @@ +#!/bin/php + + + + + + + diff --git a/pages/footer.php b/pages/footer.php new file mode 100644 index 0000000..66c16e6 --- /dev/null +++ b/pages/footer.php @@ -0,0 +1,3 @@ +#!/bin/php +
Copyright $year
+ diff --git a/pages/head.php b/pages/head.php new file mode 100644 index 0000000..4648beb --- /dev/null +++ b/pages/head.php @@ -0,0 +1 @@ +DELETEME diff --git a/pages/header.php b/pages/header.php new file mode 100644 index 0000000..b222dbe --- /dev/null +++ b/pages/header.php @@ -0,0 +1,7 @@ +#!/bin/php + + + + + + diff --git a/pages/home.js b/pages/home.js new file mode 100755 index 0000000..a3da321 --- /dev/null +++ b/pages/home.js @@ -0,0 +1,17 @@ +/* +2022-09-14 Return an example web page. + +Maybe this should this be Node or PHP/BASH? Doing HTML in Node seems gross. +*/ + +class Include { + constructor () { } + async load (request, response) { + + } +} + +include = new Include(); + +module.exports = include; + diff --git a/pages/home.php b/pages/home.php new file mode 100755 index 0000000..4b6cb4b --- /dev/null +++ b/pages/home.php @@ -0,0 +1,14 @@ +#!/bin/php + + + +

Welcome!

+ +

This is a test. It can be ignored. :)

+ + + diff --git a/pages/main.css b/pages/main.css new file mode 100644 index 0000000..e09edfd --- /dev/null +++ b/pages/main.css @@ -0,0 +1,42 @@ +/* 2022-09-14 CSS for the website. */ +/* https://www.w3schools.com/Css/css_rwd_grid.asp */ + +/* Enable dynamic stuffs */ +* { + box-sizing: border-box; +} + +/* Page Sections */ +.menu { + width: 25%; + float: left; +} +.main { + width: 75%; + float: left; +} + +.col-1 {width: 8.33%;} +.col-2 {width: 16.66%;} +.col-3 {width: 25%;} +.col-4 {width: 33.33%;} +.col-5 {width: 41.66%;} +.col-6 {width: 50%;} +.col-7 {width: 58.33%;} +.col-8 {width: 66.66%;} +.col-9 {width: 75%;} +.col-10 {width: 83.33%;} +.col-11 {width: 91.66%;} +.col-12 {width: 100%;} + +[class*="col-"] { + float: left; + padding: 15px; + border: 1px solid red; +} + +.row::after { + content: ""; + clear: both; + display: table; +} diff --git a/pages/menu.php b/pages/menu.php new file mode 100644 index 0000000..5c0ed36 --- /dev/null +++ b/pages/menu.php @@ -0,0 +1,5 @@ +#!/bin/php + + diff --git a/pages/notice.js b/pages/notice.js new file mode 100755 index 0000000..e69de29 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..c0e59f1 --- /dev/null +++ b/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# 2022-09-14 Hyperling +# Ensure dependencies are met and start the webserver. + +### 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. +if [[ ! `which php` || ! `which node` ]]; then + sudo apt install -y php-fpm nodejs +fi + +npm install + +main.js +### + +exit 0 diff --git a/test.html b/test.html new file mode 100644 index 0000000..d416aff --- /dev/null +++ b/test.html @@ -0,0 +1,27 @@ + + + + + + + Header + + + + + + + MENU + + +

Welcome!

+ +

This is a test. It can be ignored. :)

+ + +
Copyright $year
+ + + + +