Skip to content

Commit

Permalink
changed to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Mar 4, 2024
1 parent f1f82e8 commit ec7d89f
Show file tree
Hide file tree
Showing 14 changed files with 902 additions and 18,112 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Custom

/frontend/public/js*
/frontend/public/images*
/frontend/public/css*
/frontend/public/mix-manifest.json

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ ENV NODE_ENV=production
WORKDIR /app/frontend

COPY frontend/package*.json ./
RUN npm install --production
RUN npm install

COPY frontend/ ./
RUN npm run production
RUN npm run build

WORKDIR /app/backend

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is the CHS MC website that can be found here [mc.chs.se](https://mc.chs.se/
The source code for the old CHS MC website can be found here on [github](https://github.com/gudchalmers/chs-mc-website/tree/aa622740b57cfc073a5d3f4b9321ecb184ad7804).

## Development
### Backend
```shell script
cd frontend
npm install
Expand All @@ -16,7 +17,16 @@ npm install
npx nodemon index.js
```

For frontend development you probably want a better setup.
### Frontend
```shell script
cd backend
npm install
node .
cd ..
cd frontend
npm install
npm run dev
```

## Deployment

Expand Down
35 changes: 13 additions & 22 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import express from "express";
import mc from "minecraftstatuspinger";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
import crypto from "crypto";
import nodemailer from "nodemailer";
import mariadb from "mariadb";
Expand Down Expand Up @@ -41,18 +38,10 @@ const seed = async () => {
seed();

const app = express();
const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

app.use(express.static("../frontend/public")); // use public
app.use(express.static("../frontend/dist")); // use public
app.use(express.json()); // to support JSON-encoded bodies
app.use(express.urlencoded({ extended: true })); // to support URL-encoded bodies

app.get("/", (req, res) => {
const filePath = path.join(currentDirPath, "home.html");
res.sendFile(filePath);
});

const transporter = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
Expand All @@ -74,7 +63,7 @@ app.post("/register", async (req, res) => {
let username = req.body.username.toLowerCase();

// check that username is only letters and numbers or underscore
if (!/^[a-zA-Z0-9_]+$/.test(username)) {
if (!/^[a-z0-9_]+$/.test(username)) {
res.status(400).send("Invalid username");
return;
}
Expand All @@ -85,14 +74,15 @@ app.post("/register", async (req, res) => {
return;
}

let uuid = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`)
.then((response) => {
if (response.status === 404) {
res.status(400).send("Username doesn't exist");
return;
}
return response.json().id;
})
let uuid = await fetch(
`https://api.mojang.com/users/profiles/minecraft/${username}`
).then((response) => {
if (response.status === 404) {
res.status(400).send("Username doesn't exist");
return;
}
return response.json().id;
});

let token = crypto.randomBytes(32).toString("hex");

Expand Down Expand Up @@ -175,7 +165,8 @@ app.get("/ping", async (_, res) => {
let result = await mc.lookup({ host: "mc.chs.se" });
res.send(result);
} catch (error) {
res.status(500).send("An error occurred while pinging the server.");
//server is offline
res.send({ error: "Server is offline" });
}
});

Expand Down
Loading

0 comments on commit ec7d89f

Please sign in to comment.