diff --git a/.forgejo/workflows/build.yml b/.gitea/workflows/build.yml similarity index 100% rename from .forgejo/workflows/build.yml rename to .gitea/workflows/build.yml diff --git a/.gitignore b/.gitignore index ed70c70..a00b819 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,4 @@ node_modules # Config files config/config.json -.env - -# Docker -docker-compose.yml \ No newline at end of file +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8496da5..8bd562b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:21 +FROM oven/bun:latest # Install netcat RUN apt-get update && apt-get install -y netcat-traditional @@ -6,9 +6,10 @@ RUN apt-get update && apt-get install -y netcat-traditional WORKDIR /usr/src/app # Copy package.json and package-lock.json to the working directory -COPY package*.json ./ +COPY package.json ./ +copy bun.lockb ./ -RUN npm install +RUN bun install COPY . . diff --git a/Structures/Classes/Controller.js b/Structures/Classes/Controller.js new file mode 100644 index 0000000..e9ca7c6 --- /dev/null +++ b/Structures/Classes/Controller.js @@ -0,0 +1,25 @@ +//------------------------------------------------> +// Imports +//------------------------------------------------> + +// None + +//------------------------------------------------> +// Controller class +//------------------------------------------------> + +class Controller { + /** + * Construct the basis of our Controller + */ + constructor() { + this.global = { + pageData: { + name: "The Void", + links: [] + } + } + } +} + +module.exports = { Controller } \ No newline at end of file diff --git a/Structures/Classes/Model.js b/Structures/Classes/Model.js new file mode 100644 index 0000000..fb4c2e0 --- /dev/null +++ b/Structures/Classes/Model.js @@ -0,0 +1,38 @@ +//------------------------------------------------> +// Imports +//------------------------------------------------> + +// Packages +const mysql = require("mysql2"); + +// Config +const { databaseCredentials } = require("../Config/databaseCredentials"); + +//------------------------------------------------> +// Model class +//------------------------------------------------> + +class Model { + /** + * Construct the Model using the database credentials + * + * @param {Object} credentials The database credentials in a standard mysql format + */ + constructor() { + this.pool = mysql.createPool(databaseCredentials); + + this.pool.getConnection(async (err) => { + if (err) console.log(`[JET » Model] Error occurred during connection: ${err}`); + else console.log("[JET » Model » pool] Successfully initialized pool"); + }); + + this.pool.on("connection", async () => { + console.log("[JET » Model » pool] Created new connection"); + }); + + if (!this.initialize) throw new Error("[JET » Model] initialize method not found"); + this.initialize(); + } +} + +module.exports = { Model } \ No newline at end of file diff --git a/app.js b/app.js index f76d2f7..3092a7d 100644 --- a/app.js +++ b/app.js @@ -12,12 +12,16 @@ // Imports //------------------------------------------------> +// Packages const express = require("express"); const bodyParser = require("body-parser"); -const cookieParser = require("cookie-parser"); const mysql = require("mysql2"); const path = require("path"); +// Config +const { databaseCredentials } = require("./Structures/Config/databaseCredentials"); + +// Load environment variables when not using docker if (!process.env.DOCKER) { const dotenv = require("dotenv"); dotenv.config(); @@ -40,41 +44,29 @@ app.set("view engine", "ejs"); // Use body-parser and cookie-parser app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser()); //------------------------------------------------> -// MySQL connection +// Initialize database //------------------------------------------------> -//! Make extra sure these values are loaded correctly, if you experience any connection issues. -const db = mysql.createConnection({ - database: process.env.DB_NAME, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - host: process.env.DB_HOST, - port: process.env.DB_PORT +const db = mysql.createConnection(databaseCredentials); + +db.connect((err) => { + if (err) console.log(`[JET] Error occurred during initial connection: ${err}`); + else console.log("[JET] Successfully connected to database"); }); -db.connect((error) => { - if (error) { - console.error("[JET] Error connecting to MySQL database:", error); - } else { - console.log("[JET] Database connected successfully"); - } -}); +db.end(); //------------------------------------------------> // Routing //------------------------------------------------> const apiRouter = require("./routes/apiRoutes"); +const indexRouter = require("./routes/indexRoutes"); app.use("/api", apiRouter); - -// Handle home route -app.get("/", (req, res) => { - res.render("layout"); -}); +app.use("/", indexRouter); //------------------------------------------------> // Start Express diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..5575077 Binary files /dev/null and b/bun.lockb differ diff --git a/controller/placeholder b/controller/indexController.js similarity index 100% rename from controller/placeholder rename to controller/indexController.js diff --git a/model/placeholder b/controller/userController.js similarity index 100% rename from model/placeholder rename to controller/userController.js diff --git a/docker-compose.yml b/docker-compose.yml index aa66a2c..6054fb6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,12 +8,12 @@ services: environment: MYSQL_DATABASE: jet MYSQL_USER: jet - MYSQL_PASSWORD: ghiuwe§825429h§$%ff + MYSQL_PASSWORD: ghiuwe825429hff MYSQL_ROOT_PASSWORD: hgruwhgvuiwrghiuwe§825429h§$%ff ports: - "3306:3306" - volumes: - - mysql:/var/lib/mysql + # volumes: + # - mysql:/var/lib/mysql # Express app service app: @@ -28,10 +28,10 @@ services: DB_HOST: db DB_PORT: 3306 DB_USER: jet - DB_PASSWORD: ghiuwe§825429h§$%ff + DB_PASSWORD: ghiuwe§825429hff DB_NAME: jet DOCKER: true PORT: 4300 -volumes: - mysql: \ No newline at end of file +# volumes: +# mysql: \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 2f46014..2b76ede 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,4 +14,4 @@ check_database() { check_database # Start the Express app -exec npm run start +exec bun run start diff --git a/model/userModel.js b/model/userModel.js new file mode 100644 index 0000000..88489d6 --- /dev/null +++ b/model/userModel.js @@ -0,0 +1,19 @@ +//------------------------------------------------> +// Imports +//------------------------------------------------> + +const { Model } = require("../Structures/Classes/Model"); + +//------------------------------------------------> +// UserModel +//------------------------------------------------> + +class UserModel extends Model { + initialize() { + // The initialize method is required in each instance of the Model class!!! + } + + async getUserById() { + // Additional classes are optional and can be used to interact with the DB Pool, this.pool! + } +} \ No newline at end of file diff --git a/public/placeholder b/public/placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/routes/apiRoutes.js b/routes/apiRoutes.js index 1990fe4..c133f02 100644 --- a/routes/apiRoutes.js +++ b/routes/apiRoutes.js @@ -2,7 +2,7 @@ const express = require("express"); const router = express.Router(); router.get("/", (req, res) => { - // API stuff goes here :3 + // API stuff goes here }); module.exports = router; \ No newline at end of file diff --git a/routes/indexRoutes.js b/routes/indexRoutes.js new file mode 100644 index 0000000..c7660a8 --- /dev/null +++ b/routes/indexRoutes.js @@ -0,0 +1,8 @@ +const express = require("express"); +const router = express.Router(); + +router.get("/", (req, res) => { + res.render("layout"); +}); + +module.exports = router; \ No newline at end of file