Skip to content

Commit

Permalink
Merge pull request #213 from CS3219-AY2425S1/206-be-fix-nginx-routing…
Browse files Browse the repository at this point in the history
…-for-deployment-and-dev

206 be fix nginx routing for deployment and dev
  • Loading branch information
Daviancold authored Nov 9, 2024
2 parents f09194d + 600de35 commit 8929f9b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/components/dashboard/new-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const NewSession = () => {

// Refactor this
const wsUrl = (process.env.NEXT_PUBLIC_API_URL || 'ws://localhost:3006')?.concat(
`/matching/ws/?id=${websocketId}`
`/api/matching/ws/?id=${websocketId}`
)
const socket = new WebSocket(wsUrl)
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default NextAuth({

try {
const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3002',
baseURL: process.env.NEXT_PUBLIC_API_URL?.concat('/api') ?? 'http://localhost:3002',
})

const response = await api.post('/auth/login', { usernameOrEmail: username, password })
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/code/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const CodeMirrorEditor = forwardRef(({ roomId, language }: IProps, ref) => {
const token = session.user.accessToken
if (!token) return undefined
const wsProvider = new WebsocketProvider(
process.env.NEXT_PUBLIC_API_URL?.concat('/collab/y/ws') ?? 'ws://localhost:3008',
process.env.NEXT_PUBLIC_API_URL?.concat('/api/collab/y/ws') ?? 'ws://localhost:3008',
roomId,
ydoc,
{
Expand Down
10 changes: 6 additions & 4 deletions frontend/services/axios-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ const createServiceAPI = (baseURL: string) => {
return api
}

const userServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3002')
const questionServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3004')
const matchingServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3006')
const collaborationServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3008')
const userServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL?.concat('/api') ?? 'http://localhost:3002')
const questionServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL?.concat('/api') ?? 'http://localhost:3004')
const matchingServiceAPI = createServiceAPI(process.env.NEXT_PUBLIC_API_URL?.concat('/api') ?? 'http://localhost:3006')
const collaborationServiceAPI = createServiceAPI(
process.env.NEXT_PUBLIC_API_URL?.concat('/api') ?? 'http://localhost:3008'
)

export default { userServiceAPI, questionServiceAPI, matchingServiceAPI, collaborationServiceAPI }
4 changes: 4 additions & 0 deletions nginx/templates/local-nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ http {
proxy_set_header Upgrade ${D}http_upgrade;
proxy_set_header Connection "upgrade";

location /api/ {
rewrite ^/api(/.*)$ $1 last;
}

location /auth {
proxy_pass ${USER_SERVICE_URL};
}
Expand Down

0 comments on commit 8929f9b

Please sign in to comment.