Add my test project up to this point.
This commit is contained in:
parent
3da6b0a643
commit
7648f2f728
81
main.js
Executable file
81
main.js
Executable file
@ -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();
|
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"express": "^4.18.1"
|
||||
}
|
||||
}
|
8
pages/body_close.php
Normal file
8
pages/body_close.php
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/php
|
||||
|
||||
<?php
|
||||
include "footer.php"
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
12
pages/body_open.php
Normal file
12
pages/body_open.php
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/php
|
||||
|
||||
<?php
|
||||
include "header.php"
|
||||
?>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
include "menu.php"
|
||||
?>
|
||||
|
3
pages/footer.php
Normal file
3
pages/footer.php
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/php
|
||||
<h6> Copyright $year </h6>
|
||||
|
1
pages/head.php
Normal file
1
pages/head.php
Normal file
@ -0,0 +1 @@
|
||||
DELETEME
|
7
pages/header.php
Normal file
7
pages/header.php
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/php
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
|
17
pages/home.js
Executable file
17
pages/home.js
Executable file
@ -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;
|
||||
|
14
pages/home.php
Executable file
14
pages/home.php
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/php
|
||||
|
||||
<?php
|
||||
include "body_open.php";
|
||||
?>
|
||||
|
||||
<h1> Welcome! </h1>
|
||||
|
||||
<p> This is a test. It can be ignored. :) </p>
|
||||
|
||||
<?php
|
||||
include "body_close.php";
|
||||
?>
|
||||
|
42
pages/main.css
Normal file
42
pages/main.css
Normal file
@ -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;
|
||||
}
|
5
pages/menu.php
Normal file
5
pages/menu.php
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/php
|
||||
|
||||
<ul>
|
||||
<li> <a href=""> Home </a> </li>
|
||||
</ul>
|
0
pages/notice.js
Executable file
0
pages/notice.js
Executable file
17
run.sh
Executable file
17
run.sh
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user