1.1.0 • Published 3 years ago
rocket-url
Licence
ISC
Version
1.1.0
Deps
0
Size
2 kB
Vulns
0
Weekly
0
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
}
}
}