summaryrefslogtreecommitdiff
path: root/src/controller.js
diff options
context:
space:
mode:
authorMhykol <mchaeldonald62@pm.me>2026-01-08 07:23:16 -0500
committerMhykol <mchaeldonald62@pm.me>2026-01-08 07:23:16 -0500
commitf4f49cd244d2f840cbb79a9286973b5c98d4f534 (patch)
tree2d7b7111d0f998ee72a8cd0106d4609a254a125c /src/controller.js
Initial Commit
Diffstat (limited to 'src/controller.js')
-rw-r--r--src/controller.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/controller.js b/src/controller.js
new file mode 100644
index 0000000..9d81baf
--- /dev/null
+++ b/src/controller.js
@@ -0,0 +1,70 @@
+const buildPages = require('./buildpages')
+// ! Maybe write a library to create html elements
+
+class Controller {
+ constructor(data) {
+ this.baseURL = data.baseURL
+ this.data = {
+ req: data.req,
+ res: data.res
+ }
+ this.buildPages = buildPages({
+ baseURL: data.baseURL,
+ routes: new Map()
+ })
+ }
+
+ Init(data) {
+ const template = this.#GetTemplate(data)
+ return template
+ }
+
+ #GetTemplate(data) {
+ const query = new Map()
+ Object.entries(data.req.query).forEach(([key, value]) => {
+ query.set(key, value)
+ })
+
+ const object = {}
+
+ if (query.size > 0) {
+ object.req = data.req
+ object.res = data.res
+ object.path = data.path
+ object.query = query
+ object.baseURL = data.baseURL
+
+ const output = JSON.stringify(this.buildPages.Build(object))
+ return output
+ } else {
+ object.req = data.req
+ object.res = data.res
+ object.path = data.path
+ object.query = null
+ object.baseURL = data.baseURL
+
+ return this.buildPages.Template(object)
+ }
+ }
+ #GetRoutes() {
+ // ! Check if output is a `Map()`
+ const moduleObject = require(path.resolve(`${__dirname}/../config/routes`))
+ return moduleObject
+ /*
+ fs.readdirSync(path.resolve(`${__dirname}`))
+
+ const object = {
+ modulesDir: path.resolve(`${__dirname}/../routes`),
+ map: new Map()
+ }
+ object.files = fs.readdirSync(object.modulesDir).filter(file => file.endsWith('.js'))
+ const routes = new Map()
+
+
+ return
+ */
+ }
+}
+
+module.exports = (x) => {return new Controller(x)}
+