Skip to content

Commit

Permalink
Return host property from the origin variable decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Jun 5, 2023
1 parent 9acc268 commit 1572cb1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/VariableDecoder/origin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe(origin, () => {
(str) => {
const variable = new Variable('KEY', str);

const { protocol, hostname, port } = new URL(str);
const expected = { protocol, hostname, port };
const { protocol, host, hostname, port } = new URL(str);
const expected = { protocol, host, hostname, port };

expect(decoder(variable)).toStrictEqual(E.right(expected));
},
Expand Down
5 changes: 3 additions & 2 deletions src/VariableDecoder/origin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as RE from 'fp-ts/ReaderEither';

import { ask, decodeFailed, validate, VariableDecoder } from './VariableDecoder';

type Origin = Pick<URL, 'protocol' | 'hostname' | 'port'>;
type Origin = Pick<URL, 'protocol' | 'host' | 'hostname' | 'port'>;

/**
* Decodes a URL origin (scheme + hostname + port).
Expand All @@ -21,8 +21,9 @@ const origin = (): VariableDecoder<Origin> =>
),
RE.chain(validate(({ url }) => url.pathname !== '', 'must not have a pathname')),
RE.chain(validate(({ value, url }) => url.origin === value, 'must be a valid URL origin')),
RE.map(({ url: { protocol, hostname, port } }) => ({
RE.map(({ url: { protocol, host, hostname, port } }) => ({
protocol,
host,
hostname,
port,
})),
Expand Down

0 comments on commit 1572cb1

Please sign in to comment.