0

I have getServerSideProps function in NextJs12 looks like:

export const getServerSideProps: GetServerSideProps = async (ctx) => {
    const shouldRedirect = await checkPermission({ permissionCode: PERMISSION_CODES.CA_MANAGE, type: 'create' }, ctx.req.cookies[APP_SAVE_KEY.TOKEN_KEY])
    return shouldRedirect
        ? {
            props: { editId: ctx.query.id },
            redirect: shouldRedirect
        }
        : { props: { editId: ctx.query.id } }
}

My checkPermission function is:

export async function checkPermission(body: ICheckedPermisssion, token: string | undefined) {
    try {
        if (token === undefined) {
            return { destination: '/login', permanent: true }
        }
        const res = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/v1/permission-action/check`, body, {
            headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'application/json'
            }
        })
        console.log(body, token, res)
        if (res.data.data.accept === false) {
            return { destination: '/login', permanent: true }
        } else {
            return null
        }
    } catch (e) {
        console.log(e)
        return { destination: '/login', permanent: true }
    }
}

It works well in development but when I build and deploy it to test I get error connect ECONNREFUSED.

I have tried replace process.env.NEXT_PUBLIC_API_URL by directly string but didn't solve it.

My API url looks like: http://111.22.33.44:8085.
How could I do to solve this problem?

ankushlokhande
  • 870
  • 5
  • 20
Sy__26_6
  • 1
  • 2

0 Answers0