Compare commits
	
		
			2 commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a86bddf352 | |||
| b7de4d9614 | 
					 12 changed files with 115 additions and 32 deletions
				
			
		|  | @ -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 . . | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										25
									
								
								Structures/Classes/Controller.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Structures/Classes/Controller.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 } | ||||
							
								
								
									
										38
									
								
								Structures/Classes/Model.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Structures/Classes/Model.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 } | ||||
							
								
								
									
										36
									
								
								app.js
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								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
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								bun.lockb
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bun.lockb
									
										
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -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: | ||||
| # volumes: | ||||
| #   mysql: | ||||
|  | @ -14,4 +14,4 @@ check_database() { | |||
| check_database | ||||
| 
 | ||||
| # Start the Express app | ||||
| exec npm run start | ||||
| exec bun run start | ||||
|  |  | |||
							
								
								
									
										19
									
								
								model/userModel.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								model/userModel.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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!
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										8
									
								
								routes/indexRoutes.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								routes/indexRoutes.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| const express = require("express"); | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| router.get("/", (req, res) => { | ||||
|     res.render("layout"); | ||||
| }); | ||||
| 
 | ||||
| module.exports = router; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue