Did a whole ton of stuff, notably cloudflare tunnel hosting

This commit is contained in:
2025-09-18 20:31:34 -04:00
parent 0f7faa499d
commit 4fcd485e75
7 changed files with 87 additions and 24 deletions

View File

@@ -6,22 +6,32 @@ const cors = require('cors')
const app = express() const app = express()
app.use(cors()) app.use(cors({
origin: ['https://aj17thdev.nexuszone.net', 'http://localhost:5173'], // your SPA origins
credentials: true
}));
app.use(express.json()) app.use(express.json())
const port = 3000; const port = 3000;
// Mount route modules // Mount route modules
const applicationsRouter = require('./routes/applications'); const applicationsRouter = require('./routes/applications');
const { memberRanks, ranks} = require('./routes/ranks'); const { memberRanks, ranks } = require('./routes/ranks');
const members = require('./routes/users'); const members = require('./routes/members');
const loaHandler = require('./routes/loa') const loaHandler = require('./routes/loa')
const { status, memberStatus } = require('./routes/statuses')
app.use('/application', applicationsRouter); app.use('/application', applicationsRouter);
app.use('/ranks', ranks); app.use('/ranks', ranks);
app.use('/userRoles', memberRanks); app.use('/userRoles', memberRanks);
app.use('/members', members); app.use('/members', members);
app.use('/loa', loaHandler); app.use('/loa', loaHandler);
app.use('/status', status)
app.use('/memberStatus', memberStatus)
app.get('/ping', (req, res) => {
res.status(200).json({ message: 'pong' });
});
app.listen(port, () => { app.listen(port, () => {
console.log(`Example app listening on port ${port} `) console.log(`Example app listening on port ${port} `)

51
api/routes/members.js Normal file
View File

@@ -0,0 +1,51 @@
const express = require('express');
const router = express.Router();
// DB pool (same as used in api/index.js)
const pool = require('../db');
//create a new user?
router.post('/', async (req, res) => {
});
//get all users
router.get('/', async (req, res) => {
try {
const result = await pool.query('SELECT * FROM view_member_rank_status_all;');
return res.status(200).json(result);
} catch (err) {
console.error('Error fetching users:', err);
return res.status(500).json({ error: 'Failed to fetch users' });
}
});
router.get('/me', (req, res) => {
console.log(req.user);
res.json(req.user);
})
router.get('/:id', async (req, res) => {
try {
const userId = req.params.id;
const result = await pool.query('SELECT * FROM view_member_rank_status_all WHERE id = $1;', [userId]);
if (result.rows.length === 0) {
return res.status(404).json({ error: 'User not found' });
}
return res.status(200).json(result.rows[0]);
} catch (err) {
console.error('Error fetching user:', err);
return res.status(500).json({ error: 'Failed to fetch user' });
}
});
//update a user's display name (stub)
router.put('/:id/displayname', async (req, res) => {
// Stub: not implemented yet
return res.status(501).json({ error: 'Update display name not implemented' });
});
module.exports = router;

View File

@@ -69,11 +69,11 @@ export enum Status {
Accepted = "Accepted", Accepted = "Accepted",
Denied = "Denied", Denied = "Denied",
} }
// @ts-ignore
const addr = "localhost:3000" const addr = import.meta.env.VITE_APIHOST;
export async function loadApplication(id: number | string): Promise<ApplicationFull | null> { export async function loadApplication(id: number | string): Promise<ApplicationFull | null> {
const res = await fetch(`http://${addr}/application/${id}`) const res = await fetch(`${addr}/application/${id}`)
if (res.status === 204) return null if (res.status === 204) return null
if (!res.ok) throw new Error('Failed to load application') if (!res.ok) throw new Error('Failed to load application')
const json = await res.json() const json = await res.json()
@@ -86,7 +86,7 @@ export async function postApplication(val: any) {
let out = { let out = {
"App": val, "App": val,
} }
const res = await fetch(`http://${addr}/application`, { const res = await fetch(`${addr}/application`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(out), body: JSON.stringify(out),
@@ -100,7 +100,7 @@ export async function postChatMessage(message: any, post_id: number) {
message: message message: message
} }
const response = await fetch(`http://${addr}/application/${post_id}/comment`, { const response = await fetch(`${addr}/application/${post_id}/comment`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(out), body: JSON.stringify(out),
@@ -110,7 +110,7 @@ export async function postChatMessage(message: any, post_id: number) {
} }
export async function getAllApplications() { export async function getAllApplications() {
const res = await fetch(`http://${addr}/application/all`) const res = await fetch(`${addr}/application/all`)
if (res.ok) { if (res.ok) {
return res.json() return res.json()
@@ -120,7 +120,7 @@ export async function getAllApplications() {
} }
export async function approveApplication(id: Number) { export async function approveApplication(id: Number) {
const res = await fetch(`http://${addr}/application/approve/${id}`, { method: 'POST' }) const res = await fetch(`${addr}/application/approve/${id}`, { method: 'POST' })
if (!res.ok) { if (!res.ok) {
console.error("Something went wrong approving the application") console.error("Something went wrong approving the application")
@@ -128,9 +128,9 @@ export async function approveApplication(id: Number) {
} }
export async function denyApplication(id: Number) { export async function denyApplication(id: Number) {
const res = await fetch(`http://${addr}/application/deny/${id}`, { method: 'POST' }) const res = await fetch(`${addr}/application/deny/${id}`, { method: 'POST' })
if (!res.ok) { if (!res.ok) {
console.error("Something went wrong approving the application") console.error("Something went wrong denying the application")
} }
} }

View File

@@ -5,11 +5,11 @@ export type LOARequest = {
end_date: string; // ISO 8601 string end_date: string; // ISO 8601 string
reason?: string; reason?: string;
}; };
// @ts-ignore
const addr = "localhost:3000"; const addr = import.meta.env.VITE_APIHOST;
export async function submitLOA(request: LOARequest): Promise<{ id?: number; error?: string }> { export async function submitLOA(request: LOARequest): Promise<{ id?: number; error?: string }> {
const res = await fetch(`http://${addr}/loa`, { const res = await fetch(`${addr}/loa`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -25,7 +25,7 @@ export async function submitLOA(request: LOARequest): Promise<{ id?: number; err
} }
export async function getMyLOA(): Promise<LOARequest | null> { export async function getMyLOA(): Promise<LOARequest | null> {
const res = await fetch(`http://${addr}/loa/me`, { const res = await fetch(`${addr}/loa/me`, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -7,11 +7,11 @@ export type Member = {
status_date: string | null; status_date: string | null;
}; };
// @ts-ignore
const addr = "localhost:3000" const addr = import.meta.env.VITE_APIHOST;
export async function getMembers(): Promise<Member[]> { export async function getMembers(): Promise<Member[]> {
const response = await fetch(`http://${addr}/members`); const response = await fetch(`${addr}/members`);
if (!response.ok) { if (!response.ok) {
throw new Error("Failed to fetch members"); throw new Error("Failed to fetch members");
} }

View File

@@ -5,12 +5,11 @@ export type Rank = {
sortOrder: number sortOrder: number
} }
const addr = "localhost:3000" // @ts-ignore
const addr = import.meta.env.VITE_APIHOST;
// Placeholder: fetch list of ranks
export async function getRanks(): Promise<Rank[]> { export async function getRanks(): Promise<Rank[]> {
const res = await fetch(`http://${addr}/ranks`) const res = await fetch(`${addr}/ranks`)
if (res.ok) { if (res.ok) {
return res.json() return res.json()
@@ -22,7 +21,7 @@ export async function getRanks(): Promise<Rank[]> {
// Placeholder: submit a rank change // Placeholder: submit a rank change
export async function submitRankChange(memberId: number, rankId: number): Promise<{ ok: boolean }> { export async function submitRankChange(memberId: number, rankId: number): Promise<{ ok: boolean }> {
const res = await fetch(`http://${addr}/rank`, { const res = await fetch(`${addr}/rank`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -18,4 +18,7 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url)) '@': fileURLToPath(new URL('./src', import.meta.url))
}, },
}, },
server: {
allowedHosts: ["aj17thdev.nexuszone.net"]
}
}) })