1.1.0 • Published 1 year ago

rocket-url v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

This module return the real custom host when you are using AWS Amplify with custom domains on Next JS using Server Side Rendering.

Import module

import rocketUrl from 'rocket-url'

On getInitialProps

receive 'ctx' from AppContext NextJS

App.getInitialProps = async ({ ctx }) => { const { host, protocol, origin } = rocketUrl(ctx?.req)

return {
    props: {
        host,
        protocol,
        origin
    }
}

}

On getServerSideProps

receive 'req' from AppContext NextJS

export async function getServerSideProps({ req, resolvedUrl }) { const { host, protocol, origin } = rocketUrl(req) const pathname = resolvedUrl

return {
    props: {
        host,
        protocol,
        origin,
        pathname
    }
}

}