1.0.8 • Published 4 years ago

get-url-request v1.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Request Url

Extract request url from IncomingMessage (http)

Installation

npm install get-url-request
/* - OR - */
yarn add get-url-request

Usage

getHost function takes 2 arguments:

  • req typeof IncomingMessage
  • ssl boolean
import getHost from 'get-url-request'
const { host, protocol, baseUrl } = getHost(req)
import getHost from 'get-url-request'

// ...

Component.getInitialProps = (ctx: NextPageContext) => {
    const { baseUrl } = getHost(req, ssl)
    fetch(`${baseUrl}/api/endpoint`)
    // ...
}

Types

args: (req?: IncomingMessage, ssl?: boolean)
return: {
    protocol: 'http' | 'https', // example: http
    host: string, // example: 127.0.0.1:3000
    baseUrl: string // example: http://127.0.0.1:3000

License

MIT

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago