Skip to content

Commit e32bccb

Browse files
authored
Merge pull request #120 from wiredmonash/refactor-2
Configured MONSTAR for Vercel deployment
2 parents 3a634b8 + 7d66298 commit e32bccb

File tree

8 files changed

+88
-60
lines changed

8 files changed

+88
-60
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@ frontend/public/sitemap*.xml
139139
.DS_Store
140140

141141
# Swagger output
142-
backend/docs/swagger.json
142+
backend/docs/swagger.json
143+
.vercel

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

backend/server.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ cron.schedule('0 2 1 6 *', async function () {
148148
});
149149

150150
// === Catch all route (Production Mode) ===
151-
if (!isDevelopment) {
152-
app.get('*', (req, res) => {
153-
return res.sendFile(
154-
path.join(__dirname, '../frontend/dist/frontend/browser/index.html')
155-
);
156-
});
157-
}
151+
// === Export for Vercel ===
152+
module.exports = app;
158153

159-
// === Start Server ===
160-
const PORT = process.env.PORT || 8080; // Default to 8080 if no port specified
161-
app.listen(PORT, (error) => {
162-
if (error) console.log(error);
154+
// === Start Server (for local development) ===
155+
if (require.main === module) {
156+
const PORT = process.env.PORT || 8080; // Default to 8080 if no port specified
157+
app.listen(PORT, (error) => {
158+
if (error) console.log(error);
163159

164-
console.log(`Server running on port ${PORT}`);
165-
});
160+
console.log(`Server running on port ${PORT}`);
161+
});
162+
}

frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@angular/platform-browser": "^18.2.13",
1919
"@angular/platform-browser-dynamic": "^18.2.13",
2020
"@angular/router": "^18.2.13",
21-
"@swimlane/ngx-graph": "^10.0.0-alpha.0",
2221
"@tsparticles/preset-confetti": "^3.2.0",
2322
"bootstrap": "^5.3.3",
2423
"bootstrap-icons": "^1.11.3",

frontend/src/app/app.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UnitOverviewComponent } from './routes/unit-overview/unit-overview.comp
77
import { VerifiedComponent } from './routes/verified/verified.component';
88
import { NotFoundComponent } from './routes/not-found/not-found.component';
99
import { ResetPasswordComponent } from './routes/reset-password/reset-password.component';
10-
import { UnitMapComponent } from './routes/unit-map/unit-map.component';
10+
// import { UnitMapComponent } from './routes/unit-map/unit-map.component';
1111
import { TermsAndCondsComponent } from './routes/terms-and-conds/terms-and-conds.component';
1212
import { AboutComponent } from './routes/about/about.component';
1313
import { SetuOverviewComponent } from './routes/setu-overview/setu-overview.component';
@@ -21,7 +21,7 @@ export const routes: Routes = [
2121
// Unit Overview
2222
{ path: 'unit/:unitcode', component: UnitOverviewComponent },
2323
// Unit Map
24-
{ path: 'map/:unitcode', component: UnitMapComponent },
24+
// { path: 'map/:unitcode', component: UnitMapComponent },
2525
// SETU Data
2626
{ path: 'setu/:unitCode', component: SetuOverviewComponent },
2727
// Email Verification

frontend/src/app/routes/unit-map/unit-map.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
tooltipZIndex="9999"
1111
icon="pi pi-replay"
1212
rounded="true"
13-
(click)="resetGraph()"
13+
<!-- (click)="resetGraph()" -->
1414
/>
1515
</div>
1616

@@ -22,7 +22,7 @@
2222
tooltipZIndex="9999"
2323
icon="pi pi-arrow-down-left-and-arrow-up-right-to-center"
2424
rounded="true"
25-
(click)="centerGraph()"
25+
<!-- (click)="centerGraph()" -->
2626
/>
2727

2828
<p-button
@@ -32,7 +32,7 @@
3232
tooltipZIndex="9999"
3333
icon="pi pi-expand"
3434
rounded="true"
35-
(click)="resetZoom()"
35+
<!-- (click)="resetZoom()" -->
3636
/>
3737
</div>
3838

@@ -44,7 +44,7 @@
4444
tooltipZIndex="9999"
4545
icon="pi pi-wave-pulse"
4646
rounded="true"
47-
(click)="toggleLayout()"
47+
<!-- (click)="toggleLayout()" -->
4848
/>
4949
</div>
5050
</p-toolbar>
@@ -65,7 +65,7 @@ <h1>{{ unit?.unitCode | uppercase }}</h1>
6565
icon="pi pi-arrow-left"
6666
[rounded]="true"
6767
[text]="true"
68-
(click)="navigateBack()"
68+
<!-- (click)="navigateBack()" -->
6969
styleClass="p-button-secondary"
7070
pTooltip="Go back"
7171
tooltipPosition="right"
@@ -179,9 +179,9 @@ <h3>{{ unit?.name }}</h3>
179179
</defs>
180180
</svg>
181181

182-
<!-- ! Graph -->
183-
<ngx-graph
184-
[view]="[graphContainer.offsetWidth, graphContainer.offsetHeight]"
182+
<!-- ! Graph - Temporarily disabled due to dependency conflicts -->
183+
<!-- <ngx-graph
184+
[view]="[graphContainer.offsetWidth, graphContainer.offsetHeight]"
185185
[links]="edges"
186186
[nodes]="nodes"
187187
[layout]="layout"
@@ -218,7 +218,7 @@ <h3>{{ unit?.name }}</h3>
218218
/>
219219
</svg:g>
220220
</ng-template>
221-
</ngx-graph>
221+
<!-- </ngx-graph> -->
222222

223223
<!-- ! The loading overlay screen (this must be put here) -->
224224
@if (isLoading) {

frontend/src/app/routes/unit-map/unit-map.component.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Location } from '@angular/common';
33
import { OrganizationChartModule } from 'primeng/organizationchart';
44
import { ApiService } from '../../shared/services/api.service';
55
import { Router } from '@angular/router';
6-
import { Edge, NgxGraphModule, NgxGraphZoomOptions } from '@swimlane/ngx-graph';
6+
// import { Edge, NgxGraphModule, NgxGraphZoomOptions } from '@swimlane/ngx-graph';
77
import * as shape from 'd3-shape';
88
import { Subject } from 'rxjs';
99
import { ButtonModule } from 'primeng/button';
@@ -30,21 +30,21 @@ interface UnitNode {
3030

3131
/**
3232
* * Unit Edge Interface
33-
*
33+
*
3434
* An interface for the edges in the unit graph
3535
*/
36-
interface UnitEdge extends Edge {
37-
data?: {
38-
type: 'prerequisite' | 'parent';
39-
}
40-
}
36+
// interface UnitEdge extends Edge {
37+
// data?: {
38+
// type: 'prerequisite' | 'parent';
39+
// }
40+
// }
4141

4242
@Component({
4343
selector: 'app-unit-map',
4444
standalone: true,
4545
imports: [
4646
OrganizationChartModule,
47-
NgxGraphModule,
47+
// NgxGraphModule,
4848
ButtonModule,
4949
ToolbarModule,
5050
TooltipModule,
@@ -58,13 +58,13 @@ interface UnitEdge extends Edge {
5858
export class UnitMapComponent implements OnInit, OnDestroy {
5959
@ViewChild('graphContainer') graphContainer!: ElementRef;
6060

61-
nodes: UnitNode[] = [];
62-
edges: UnitEdge[] = [];
61+
// nodes: UnitNode[] = [];
62+
// edges: UnitEdge[] = [];
6363
layout = 'dagre';
6464
curve = shape.curveBasis;
6565

6666
center$: Subject<boolean> = new Subject();
67-
zoomToFit$: Subject<NgxGraphZoomOptions> = new Subject();
67+
// zoomToFit$: Subject<NgxGraphZoomOptions> = new Subject();
6868

6969
isLoading: boolean = false;
7070

@@ -142,7 +142,7 @@ export class UnitMapComponent implements OnInit, OnDestroy {
142142

143143
// Initalise arrays for prerequisites
144144
let prereqNodes: UnitNode[] = [];
145-
let prereqEdges: UnitEdge[] = [];
145+
// let prereqEdges: UnitEdge[] = [];
146146

147147
// Only process prerequisites if they exist
148148
if (unit.requisites?.prerequisites && unit.requisites.prerequisites.length > 0) {
@@ -161,17 +161,17 @@ export class UnitMapComponent implements OnInit, OnDestroy {
161161
this.prerequisiteNumReq = unit.requisites.prerequisites[0].NumReq;
162162

163163
// Add prerequisite edges
164-
prereqEdges = prereqNodes.map(node => ({
165-
id: `${node.id}-${currentNode.id}`,
166-
source: node.id,
167-
target: currentNode.id,
168-
data: { type: 'prerequisite' }
169-
}));
164+
// prereqEdges = prereqNodes.map(node => ({
165+
// id: `${node.id}-${currentNode.id}`,
166+
// source: node.id,
167+
// target: currentNode.id,
168+
// data: { type: 'prerequisite' }
169+
// }));
170170
}
171171

172172
// Set initial nodes and edges
173-
this.nodes = [currentNode, ...prereqNodes];
174-
this.edges = prereqEdges;
173+
// this.nodes = [currentNode, ...prereqNodes];
174+
// this.edges = prereqEdges;
175175

176176

177177
// Fetch the units that are required by the current unit
@@ -197,7 +197,7 @@ export class UnitMapComponent implements OnInit, OnDestroy {
197197
// console.log('Parent nodes:', parentNodes);
198198

199199
// Add edges from current node to parent nodes
200-
const parentEdges: UnitEdge[] = parentNodes.map(node => ({
200+
// const parentEdges: UnitEdge[] = parentNodes.map(node => ({
201201
id: `${currentNode.id}-${node.id}`,
202202
source: currentNode.id,
203203
target: node.id,
@@ -208,8 +208,8 @@ export class UnitMapComponent implements OnInit, OnDestroy {
208208
// console.log('Parent edges:', parentEdges);
209209

210210
// Add parent nodes and edges to the graph
211-
this.nodes = [...this.nodes, ...parentNodes];
212-
this.edges = [...this.edges, ...parentEdges];
211+
// this.nodes = [...this.nodes, ...parentNodes];
212+
// this.edges = [...this.edges, ...parentEdges];
213213

214214
// ? Debug log: Final graph state
215215
// console.log('Final graph state:', {
@@ -218,22 +218,22 @@ export class UnitMapComponent implements OnInit, OnDestroy {
218218
// });
219219

220220
// Center the graph
221-
this.centerGraph();
221+
// this.centerGraph();
222222
}
223223
});
224224
}
225225
});
226226

227227
// Zoom to fit
228-
this.resetZoom();
228+
// this.resetZoom();
229229
}
230230

231231
/**
232232
* * Centers the Graph
233233
*/
234-
centerGraph() {
235-
this.center$.next(true);
236-
}
234+
// centerGraph() {
235+
// this.center$.next(true);
236+
// }
237237

238238
/**
239239
* * Resets the Graph
@@ -246,16 +246,16 @@ export class UnitMapComponent implements OnInit, OnDestroy {
246246
/**
247247
* * Zoom to Fit
248248
*/
249-
resetZoom() {
250-
this.zoomToFit$.next({ force: true, autoCenter: true });
251-
}
249+
// resetZoom() {
250+
// // this.zoomToFit$.next({ force: true, autoCenter: true });
251+
// }
252252

253253
/**
254254
* * Toggle Layout
255255
*/
256-
toggleLayout() {
257-
this.layout = this.layout === 'dagre' ? 'colaForceDirected' : 'dagre';
258-
}
256+
// toggleLayout() {
257+
// this.layout = this.layout === 'dagre' ? 'colaForceDirected' : 'dagre';
258+
// }
259259

260260
/**
261261
* * Navigates back to the previous page

vercel.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": 2,
3+
"builds": [
4+
{
5+
"src": "backend/server.js",
6+
"use": "@vercel/node"
7+
},
8+
{
9+
"src": "frontend/package.json",
10+
"use": "@vercel/static-build",
11+
"config": {
12+
"distDir": "dist/frontend/browser",
13+
"buildCommand": "npm install --legacy-peer-deps && npm run build"
14+
}
15+
}
16+
],
17+
"routes": [
18+
{
19+
"src": "/api/(.*)",
20+
"dest": "/backend/server.js"
21+
},
22+
{
23+
"src": "/(.*)",
24+
"dest": "/frontend/$1"
25+
}
26+
],
27+
"env": {
28+
"PRODUCTION_MACHINE": "false"
29+
}
30+
}

0 commit comments

Comments
 (0)