Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
a86bddf352 | |||
b7de4d9614 |
15 changed files with 117 additions and 37 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -3,7 +3,4 @@ node_modules
|
||||||
|
|
||||||
# Config files
|
# Config files
|
||||||
config/config.json
|
config/config.json
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# Docker
|
|
||||||
docker-compose.yml
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:21
|
FROM oven/bun:latest
|
||||||
|
|
||||||
# Install netcat
|
# Install netcat
|
||||||
RUN apt-get update && apt-get install -y netcat-traditional
|
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
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Copy package.json and package-lock.json to the working directory
|
# 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 . .
|
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
|
// Imports
|
||||||
//------------------------------------------------>
|
//------------------------------------------------>
|
||||||
|
|
||||||
|
// Packages
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
const cookieParser = require("cookie-parser");
|
|
||||||
const mysql = require("mysql2");
|
const mysql = require("mysql2");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
// Config
|
||||||
|
const { databaseCredentials } = require("./Structures/Config/databaseCredentials");
|
||||||
|
|
||||||
|
// Load environment variables when not using docker
|
||||||
if (!process.env.DOCKER) {
|
if (!process.env.DOCKER) {
|
||||||
const dotenv = require("dotenv");
|
const dotenv = require("dotenv");
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
@ -40,41 +44,29 @@ app.set("view engine", "ejs");
|
||||||
|
|
||||||
// Use body-parser and cookie-parser
|
// Use body-parser and cookie-parser
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
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(databaseCredentials);
|
||||||
const db = mysql.createConnection({
|
|
||||||
database: process.env.DB_NAME,
|
db.connect((err) => {
|
||||||
user: process.env.DB_USER,
|
if (err) console.log(`[JET] Error occurred during initial connection: ${err}`);
|
||||||
password: process.env.DB_PASSWORD,
|
else console.log("[JET] Successfully connected to database");
|
||||||
host: process.env.DB_HOST,
|
|
||||||
port: process.env.DB_PORT
|
|
||||||
});
|
});
|
||||||
|
|
||||||
db.connect((error) => {
|
db.end();
|
||||||
if (error) {
|
|
||||||
console.error("[JET] Error connecting to MySQL database:", error);
|
|
||||||
} else {
|
|
||||||
console.log("[JET] Database connected successfully");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//------------------------------------------------>
|
//------------------------------------------------>
|
||||||
// Routing
|
// Routing
|
||||||
//------------------------------------------------>
|
//------------------------------------------------>
|
||||||
|
|
||||||
const apiRouter = require("./routes/apiRoutes");
|
const apiRouter = require("./routes/apiRoutes");
|
||||||
|
const indexRouter = require("./routes/indexRoutes");
|
||||||
|
|
||||||
app.use("/api", apiRouter);
|
app.use("/api", apiRouter);
|
||||||
|
app.use("/", indexRouter);
|
||||||
// Handle home route
|
|
||||||
app.get("/", (req, res) => {
|
|
||||||
res.render("layout");
|
|
||||||
});
|
|
||||||
|
|
||||||
//------------------------------------------------>
|
//------------------------------------------------>
|
||||||
// Start Express
|
// Start Express
|
||||||
|
|
BIN
bun.lockb
Executable file
BIN
bun.lockb
Executable file
Binary file not shown.
|
@ -8,12 +8,12 @@ services:
|
||||||
environment:
|
environment:
|
||||||
MYSQL_DATABASE: jet
|
MYSQL_DATABASE: jet
|
||||||
MYSQL_USER: jet
|
MYSQL_USER: jet
|
||||||
MYSQL_PASSWORD: ghiuwe§825429h§$%ff
|
MYSQL_PASSWORD: ghiuwe825429hff
|
||||||
MYSQL_ROOT_PASSWORD: hgruwhgvuiwrghiuwe§825429h§$%ff
|
MYSQL_ROOT_PASSWORD: hgruwhgvuiwrghiuwe§825429h§$%ff
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- "3306:3306"
|
||||||
volumes:
|
# volumes:
|
||||||
- mysql:/var/lib/mysql
|
# - mysql:/var/lib/mysql
|
||||||
|
|
||||||
# Express app service
|
# Express app service
|
||||||
app:
|
app:
|
||||||
|
@ -28,10 +28,10 @@ services:
|
||||||
DB_HOST: db
|
DB_HOST: db
|
||||||
DB_PORT: 3306
|
DB_PORT: 3306
|
||||||
DB_USER: jet
|
DB_USER: jet
|
||||||
DB_PASSWORD: ghiuwe§825429h§$%ff
|
DB_PASSWORD: ghiuwe§825429hff
|
||||||
DB_NAME: jet
|
DB_NAME: jet
|
||||||
DOCKER: true
|
DOCKER: true
|
||||||
PORT: 4300
|
PORT: 4300
|
||||||
|
|
||||||
volumes:
|
# volumes:
|
||||||
mysql:
|
# mysql:
|
|
@ -14,4 +14,4 @@ check_database() {
|
||||||
check_database
|
check_database
|
||||||
|
|
||||||
# Start the Express app
|
# 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!
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ const express = require("express");
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req, res) => {
|
||||||
// API stuff goes here :3
|
// API stuff goes here
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
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…
Reference in a new issue