Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
false-fox committed May 4, 2024
0 parents commit 882ac05
Show file tree
Hide file tree
Showing 27 changed files with 2,386 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Fortran.JS Web framework
The best motherfucking web framework for human-driven websites.

Harness the blazingly fast speed 🚀🚀🚀, simplicity 🪑 and security 🔒 of fortran for your next web development project TODAY.

## Features
- Blazingly fast speeds 🚀🚀🚀. Fortran.JS is compiled to machine code and executed on demand.
- Simplicity 🪑 Web frameworks have become too bloated and slow, Fortran.JS breathes a sigh of relief to overworked developers looking for yet another new framework.
- Security by obscurity 🔒 Hackers and bad actors don't even know fortran, so how are they going to cause data breaches?

## Custom web server
The custom web server is written in Node.JS, and has custom developer tools, such as:
- A dev server with automatic building and reloading on changes 🚀🚀🚀
- A smart compiler that handles everything for you, like compiler options for components. 🚀🚀🚀
- Support for external files in a /public/ directory 🚀🚀🚀
- Supports components like in less advanced frameworks like react 🚀🚀🚀



## Code example:
```fortran
! webapp.f90
program home
implicit none
character(len=*), parameter :: Head = '<!doctype html>' //&
'<html lang="en">' //&
'<body>'
print '(a)', Head
character(len=*), parameter :: some_dynamic_text = 'Hello, from Fortran!'
print '(a)', '<h1>', some_dynamic_text, '</h1>'
print '(a)', '</body></html>'
end program home
```

## Demo
The repository comes with, by default, an advanced demo featuring components and dynamic text in action.

![Alt text](image.png)

## Prereqs
- linux computer (no spawn-fcgi on windows)
- [spawn-fcgi](https://github.com/lighttpd/spawn-fcgi) (build from source or install from package manager)
- nodejs and npm
- the [fortran language](https://fortran-lang.org/learn/os_setup/install_gfortran/)

## Install
1. Don't
2. Install spawn-fcgi, nodejs and fortran for your system
3. Use "npm run dev" to run a development server that'll auto rebuild
4. Use "npm run build" to build the server
5. Use "npm run start" to run the server.

## Yes this is satire!
I made this as a joke a year or two ago. I am still ashamed.

## Works cited:
[1] *Observation of Einstein-Podolsky-Rosen Entanglement on Supraquantum Structures by Induction Through Nonlinear Transuranic Crystal of Extremely Long Wavelength (ELW) Pulse from Mode-Locked Source Array* (Freeman, Gordon 1992)

[2] ![Alt text](/public/proof.png)
106 changes: 106 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const fs = require("fs")
const path = require("path");
const {
exec
} = require("child_process");
const readline = require('readline');

exec("rm -r ./build/")

async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
}
}

async function compile(p) {
//p should be formatted as /path/to/file.f90

//Return if it's not a fortran file
if (!p.toStringreloading().endsWith(".f90")) return;

// Default output name
let output = 'index'

let name = p.split("/").pop()

let path = p.split("/")
path.pop()

//Reservered word exemptions
if (name === "404.f90") {
output = "404"
}

console.log(`Compiling ${name} at ${path.join("/")}....` )

let compilerOptions = [""]

//Spaghetti here

const fileStream = fs.createReadStream(`./${path.join("/") + "/" + name}`);

const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
// Note: we use the crlfDelay option to recognize all instances of CR LF
// ('\r\n') in input.txt as a single line break.

for await (const line of rl) {
// Each line in input.txt will be successively available here as `line`.
if (line.match(/(USE c)/)) {

let splitline = line.split("_")
console.log("Importing modules...")

compilerOptions.push(`./components/${splitline[1]}/${splitline[1]}.f90`)




} else continue;

if (line.match(/(character)/)) break;
}


console.log("Creating the output directory...")


exec(`mkdir -p ./build/${path.join("/")}`, function (err, stdout, stderr) {
if (err) {
console.error("----------------------------\n Error occured while trying to create build directory\n----------------------------\n")
console.error(err)
}
})

console.log("Compiling....")

exec(`gfortran -ffree-form ${compilerOptions.join(" ")} ./${path.join("/") + "/" + name} -o ./build/${path.join("/")}/${output}`, function (err, stdout, stderr) {
if (err) {
console.error("----------------------------\n Error occured while compiling pages\n----------------------------\n")
console.error(err)
} else {
console.log(`${name} compiled successfully!`)
}
})
}

async function main() {

for await (const p of walk('./pages')) {
if (!p.toString().endsWith(".f90")) continue;


compile(p)
}
}

main()

module.exports = {
compile: compile
}
Binary file added build/pages/404
Binary file not shown.
Binary file added build/pages/docs/index
Binary file not shown.
Binary file added build/pages/index
Binary file not shown.
Binary file added build/pages/ping/index
Binary file not shown.
Binary file added c_footer.mod
Binary file not shown.
Binary file added c_header.mod
Binary file not shown.
Binary file added c_paragraph.mod
Binary file not shown.
Binary file added components/footer/c_footer.mod
Binary file not shown.
15 changes: 15 additions & 0 deletions components/footer/footer.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MODULE c_footer
IMPLICIT NONE
PRIVATE

PUBLIC :: footer

CONTAINS

SUBROUTINE footer()
PRINT '(a)', "<p>Copyright 2022 (C) falsefox</p></body></html>"
END SUBROUTINE footer



END MODULE c_footer
Binary file added components/header/c_header.mod
Binary file not shown.
21 changes: 21 additions & 0 deletions components/header/header.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MODULE c_header
IMPLICIT NONE
PRIVATE
PUBLIC :: header


CONTAINS
SUBROUTINE header()
character(len=*), parameter :: HeaderContent = ""//&
"<div id='headerContainer'>"//&
"Webtran <a href='/#'>Home</a> <a href='/docs'>Documentation</a>"//&
"</div>"

print '(a)', HeaderContent

END SUBROUTINE header



END MODULE c_header

Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const express = require('express')
const app = express()
const fs = require("fs")
const path = require("path");
const {
exec
} = require("child_process")
//Compile to build


const port = 3000
app.use('/public', express.static('public'));
app.use('/styles', express.static('styles'));


function test(req, res, next) {

exec(`spawn-fcgi -n -a 127.0.0.1 -p 9000 ./build/pages${req.originalUrl}/index`, function (err, stdout, stderr) {

if (err) {

exec(`spawn-fcgi -n -a 127.0.0.1 -p 9000 ./build/pages/404`, function (err, stdout2, stderr) {
if (err) {
console.error("----------------------------\n Error occured while fetching 404 page, are your paths set correctly?\n----------------------------\n")
console.error(err)
}
res.send(stdout2)
})
console.log(err)

} else {
res.send(stdout)
}

})
}

app.get("/*", test);

app.listen(port, () => {
console.log(`Webserver is live at localhost:${port}!`)
})
Loading

0 comments on commit 882ac05

Please sign in to comment.