Just make me
endpoint forward the backend response
This commit is contained in:
parent
cfeb50826c
commit
b83caf4dd9
|
@ -1,7 +1,6 @@
|
|||
import { User } from 'common/user'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { fetchBackend } from 'web/lib/api/proxy'
|
||||
import { LiteUser, ApiError, toLiteUser } from './_types'
|
||||
import { fetchBackend, forwardResponse } from 'web/lib/api/proxy'
|
||||
import { LiteUser, ApiError } from './_types'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
|
@ -9,15 +8,7 @@ export default async function handler(
|
|||
) {
|
||||
try {
|
||||
const backendRes = await fetchBackend(req, 'getcurrentuser')
|
||||
|
||||
const user = (await backendRes.json()) as User
|
||||
if (!user) {
|
||||
res.status(404).json({ error: 'User not found' })
|
||||
return
|
||||
}
|
||||
res.setHeader('Cache-Control', 'no-cache')
|
||||
res.status(200).json(toLiteUser(user))
|
||||
return
|
||||
await forwardResponse(res, backendRes)
|
||||
} catch (err) {
|
||||
console.error('Error talking to cloud function: ', err)
|
||||
res.status(500).json({ error: 'Error communicating with backend.' })
|
||||
|
|
Loading…
Reference in New Issue
Block a user