Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @remarks
* An instance is available in `InitContext.config`. Configuration
* classes must be decorated with `class-transformer` (`@Expose`, `@Default`)
* and `class-validator` (`@IsPort`, `@IsIpOrFQDN`, etc.) decorators from
* and `class-validator` (`@IsPort`, `@IsIpOrURL`, etc.) decorators from
* `@nanoforge-dev/config`.
*
* @example
Expand Down
4 changes: 2 additions & 2 deletions packages/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import {
Default,
Expose,
IsByteLength,
IsIpOrFQDN,
IsIpOrURL,
IsOptional,
IsPort,
} from "@nanoforge-dev/config";
Expand All @@ -120,7 +120,7 @@ export class ClientConfigNetwork {

// This var must be ip address or fqdn (it cannot be undefined)
@Expose()
@IsIpOrFQDN()
@IsIpOrURL()
SERVER_ADDRESS?: string;

// This var must be a byte length between 2 and 64. It can be undefined as it as a default value.
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/validators/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { IsIpOrFQDN } from "./is-ip-or-fqdn.validator";
export { IsIpOrURL } from "./is-ip-or-url.validator";
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ValidationOptions, isFQDN, isIP, registerDecorator } from "class-validator";
import { type ValidationOptions, isIP, isURL, registerDecorator } from "class-validator";

/**
* Property decorator that validates whether the value is a valid IPv4/IPv6
* address or a fully qualified domain name (FQDN).
* address or a fully qualified domain name (URL).
*
* @remarks
* Built on top of `class-validator`'s `isIP` and `isFQDN` helpers. Use on
* Built on top of `class-validator`'s `isIP` and `isURL` helpers. Use on
* config properties that represent server hostnames or addresses.
*
* @param validationOptions - Optional class-validator validation options.
Expand All @@ -14,12 +14,12 @@ import { type ValidationOptions, isFQDN, isIP, registerDecorator } from "class-v
* ```ts
* class MyConfig {
* \@Expose()
* \@IsIpOrFQDN()
* \@IsIpOrURL()
* SERVER_ADDRESS!: string;
* }
* ```
*/
export const IsIpOrFQDN = (validationOptions?: ValidationOptions) => {
export const IsIpOrURL = (validationOptions?: ValidationOptions) => {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
Expand All @@ -28,10 +28,10 @@ export const IsIpOrFQDN = (validationOptions?: ValidationOptions) => {
constraints: [],
validator: {
validate(value: string) {
return isIP(value) || isFQDN(value);
return isIP(value) || isURL(value);
},
defaultMessage() {
return `$value must be a valid IP address or FQDN`;
return `$value must be a valid IP address or URL`;
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/network-client/src/config.client.network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Expose,
IsBoolean,
IsByteLength,
IsIpOrFQDN,
IsIpOrURL,
IsOptional,
IsPort,
TransformToBoolean,
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ClientConfigNetwork {

/** Hostname or IP address of the game server. */
@Expose()
@IsIpOrFQDN()
@IsIpOrURL()
SERVER_ADDRESS!: string;

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/network-server/src/config.server.network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Default,
Expose,
IsByteLength,
IsIpOrFQDN,
IsIpOrURL,
IsOptional,
IsPort,
IsString,
Expand Down Expand Up @@ -46,7 +46,7 @@ export class ServerConfigNetwork {
*/
@Expose()
@Default("0.0.0.0")
@IsIpOrFQDN()
@IsIpOrURL()
LISTENING_INTERFACE!: string;

/**
Expand Down
Loading