Skip to content

Commit 6e587f5

Browse files
committed
Temporary fix for question view fetch fail
1 parent 9ff311b commit 6e587f5

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

nginx/nginx.conf

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ events {
88
http {
99
include mime.types;
1010
default_type application/octet-stream;
11+
# for caching of cookie
12+
proxy_cache_path cache/ keys_zone=auth_cache:1m;
1113

1214
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
1315
# '$status $body_bytes_sent "$http_referer" '
@@ -27,19 +29,46 @@ http {
2729
listen 80;
2830
server_name localhost;
2931

30-
# frontend
32+
# frontend (i guess login page)
3133
location / {
32-
proxy_pass http://localhost:3000; # frontend running on...similar for other services
34+
proxy_pass http://localhost:3000/; # frontend running on...similar for other services
35+
proxy_http_version 1.1;
36+
proxy_set_header Upgrade $http_upgrade;
37+
proxy_set_header Connection "Upgrade";
38+
proxy_set_header Host $host;
39+
proxy_cache_bypass $http_upgrade;
3340
}
3441

3542
# question
3643
location /api/ {
3744
proxy_pass http://localhost:9090/;
3845
}
3946

40-
# user
41-
location /users/ {
42-
proxy_pass http://localhost:3001/;
43-
}
47+
# # user (pure conjecture, just referencing gaylord article)
48+
# location /users/ {
49+
# auth_request auth;
50+
# auth_request_set $userid $upstream_http_x_auth_user;
51+
52+
# # if fail go back to landing
53+
# if ($http_accept ~* "text/html" ) {
54+
# error_page 401 403 =200 /;
55+
# }
56+
# proxy_set_header X-Auth-User $userid;
57+
# proxy_set_header Host $host;
58+
# proxy_set_header X-Forwarded-For $remote_addr;
59+
# proxy_pass http://localhost:3001/;
60+
61+
# }
62+
63+
# location = auth {
64+
# internal;
65+
# # proxy_pass to authenticator service
66+
# proxy_set_header Content-Length "";
67+
# proxy_set_header X-Dbg $cookie_AUTH;
68+
69+
# proxy_cache auth_cache;
70+
# proxy_cache_valid 200 204 1m;
71+
# proxy_cache_key "$http_authorization"; # jwt?
72+
# }
4473
}
4574
}

peerprep/.env.sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# THIS CANNOT BE RIGHT, TEMP FIX
2+
NEXT_PUBLIC_BASE_URL=http://localhost
13
# location of question service
24
NEXT_PUBLIC_QUESTION_SERVICE=api
3-
NEXT_PUBLIC_QUESTION_SERVICE=users
5+
NEXT_PUBLIC_USER_SERVICE=users
46
# dev flag, originally used when services were not up
57
DEV_ENV=not

peerprep/api/gateway.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const questions: { [key: string]: Question } = {
2828
},
2929
};
3030

31+
const apiHome = `${process.env.NEXT_PUBLIC_BASE_URL}/${process.env.NEXT_PUBLIC_QUESTION_SERVICE}`;
32+
3133
export async function fetchQuestion(
3234
questionId: string
3335
): Promise<Question | StatusBody> {
@@ -38,9 +40,7 @@ export async function fetchQuestion(
3840
: questions[questionId];
3941
}
4042
try {
41-
const response = await fetch(
42-
`${process.env.NEXT_PUBLIC_QUESTION_SERVICE}/questions/solve/${questionId}`
43-
);
43+
const response = await fetch(`${apiHome}/questions/solve/${questionId}`);
4444
if (!response.ok) {
4545
return {
4646
error: await response.text(),
@@ -109,9 +109,7 @@ export async function deleteQuestion(question: Question): Promise<StatusBody> {
109109

110110
export async function getAllQuestions(): Promise<Question[] | StatusBody> {
111111
try {
112-
const response = await fetch(
113-
`${process.env.NEXT_PUBLIC_QUESTION_SERVICE}/questions`
114-
);
112+
const response = await fetch(`${apiHome}/questions`);
115113
if (!response.ok) {
116114
return {
117115
error: await response.text(),

peerprep/components/questionpage/QuestionCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use client";
21
import { deleteQuestion } from "@/api/gateway";
32
import React from "react";
43
import { Question, Difficulty } from "@/api/structs";
54
import PeerprepButton from "../shared/PeerprepButton";
65
import { useRouter } from "next/navigation";
76
import styles from "@/style/questionCard.module.css";
8-
import QuestionList from "./QuestionList";
97

108
type QuestionCardProps = {
119
question: Question;
@@ -71,7 +69,9 @@ const QuestionCard: React.FC<QuestionCardProps> = ({ question }) => {
7169
</div>
7270

7371
<div className={styles.buttonContainer}>
74-
<PeerprepButton onClick={() => router.push(`questions/${question.id}`)}>
72+
<PeerprepButton
73+
onClick={() => router.push(`/questions/${question.id}`)}
74+
>
7575
View
7676
</PeerprepButton>
7777
<PeerprepButton onClick={handleDelete}>Delete</PeerprepButton>

0 commit comments

Comments
 (0)