Did a whole ton of stuff, notably cloudflare tunnel hosting
This commit is contained in:
16
api/index.js
16
api/index.js
@@ -6,22 +6,32 @@ const cors = require('cors')
|
||||
|
||||
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())
|
||||
|
||||
const port = 3000;
|
||||
|
||||
// Mount route modules
|
||||
const applicationsRouter = require('./routes/applications');
|
||||
const { memberRanks, ranks} = require('./routes/ranks');
|
||||
const members = require('./routes/users');
|
||||
const { memberRanks, ranks } = require('./routes/ranks');
|
||||
const members = require('./routes/members');
|
||||
const loaHandler = require('./routes/loa')
|
||||
const { status, memberStatus } = require('./routes/statuses')
|
||||
|
||||
app.use('/application', applicationsRouter);
|
||||
app.use('/ranks', ranks);
|
||||
app.use('/userRoles', memberRanks);
|
||||
app.use('/members', members);
|
||||
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, () => {
|
||||
console.log(`Example app listening on port ${port} `)
|
||||
|
||||
51
api/routes/members.js
Normal file
51
api/routes/members.js
Normal 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;
|
||||
@@ -69,11 +69,11 @@ export enum Status {
|
||||
Accepted = "Accepted",
|
||||
Denied = "Denied",
|
||||
}
|
||||
|
||||
const addr = "localhost:3000"
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
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.ok) throw new Error('Failed to load application')
|
||||
const json = await res.json()
|
||||
@@ -86,7 +86,7 @@ export async function postApplication(val: any) {
|
||||
let out = {
|
||||
"App": val,
|
||||
}
|
||||
const res = await fetch(`http://${addr}/application`, {
|
||||
const res = await fetch(`${addr}/application`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(out),
|
||||
@@ -100,7 +100,7 @@ export async function postChatMessage(message: any, post_id: number) {
|
||||
message: message
|
||||
}
|
||||
|
||||
const response = await fetch(`http://${addr}/application/${post_id}/comment`, {
|
||||
const response = await fetch(`${addr}/application/${post_id}/comment`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(out),
|
||||
@@ -110,7 +110,7 @@ export async function postChatMessage(message: any, post_id: number) {
|
||||
}
|
||||
|
||||
export async function getAllApplications() {
|
||||
const res = await fetch(`http://${addr}/application/all`)
|
||||
const res = await fetch(`${addr}/application/all`)
|
||||
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
@@ -120,7 +120,7 @@ export async function getAllApplications() {
|
||||
}
|
||||
|
||||
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) {
|
||||
console.error("Something went wrong approving the application")
|
||||
@@ -128,9 +128,9 @@ export async function approveApplication(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) {
|
||||
console.error("Something went wrong approving the application")
|
||||
console.error("Something went wrong denying the application")
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@ export type LOARequest = {
|
||||
end_date: string; // ISO 8601 string
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
const addr = "localhost:3000";
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
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",
|
||||
headers: {
|
||||
"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> {
|
||||
const res = await fetch(`http://${addr}/loa/me`, {
|
||||
const res = await fetch(`${addr}/loa/me`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -7,11 +7,11 @@ export type Member = {
|
||||
status_date: string | null;
|
||||
};
|
||||
|
||||
|
||||
const addr = "localhost:3000"
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
export async function getMembers(): Promise<Member[]> {
|
||||
const response = await fetch(`http://${addr}/members`);
|
||||
const response = await fetch(`${addr}/members`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch members");
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@ export type Rank = {
|
||||
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[]> {
|
||||
const res = await fetch(`http://${addr}/ranks`)
|
||||
const res = await fetch(`${addr}/ranks`)
|
||||
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
@@ -22,7 +21,7 @@ export async function getRanks(): Promise<Rank[]> {
|
||||
|
||||
// Placeholder: submit a rank change
|
||||
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",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -18,4 +18,7 @@ export default defineConfig({
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
},
|
||||
},
|
||||
server: {
|
||||
allowedHosts: ["aj17thdev.nexuszone.net"]
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user