Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the target length as env variable #666

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DEFAULT_DOMAIN=localhost:3000

# Generated link length
LINK_LENGTH=6
MAX_TARGET_LENGTH=2040

# Postgres database credential details
DB_HOST=postgres
Expand Down
2 changes: 1 addition & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DEFAULT_DOMAIN=localhost:3000

# Generated link length
LINK_LENGTH=6

MAX_TARGET_LENGTH=2040
# Postgres database credential details
DB_HOST=localhost
DB_PORT=5432
Expand Down
1 change: 1 addition & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const env = cleanEnv(process.env, {
SITE_NAME: str({ example: "Kutt" }),
DEFAULT_DOMAIN: str({ example: "kutt.it" }),
LINK_LENGTH: num({ default: 6 }),
MAX_TARGET_LENGTH: num({ default: 2040 }),
DB_HOST: str({ default: "localhost" }),
DB_PORT: num({ default: 5432 }),
DB_NAME: str({ default: "postgres" }),
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const createLink = [
.withMessage("Target is missing.")
.isString()
.trim()
.isLength({ min: 1, max: 2040 })
.withMessage("Maximum URL length is 2040.")
.isLength({ min: 1, max: env.MAX_TARGET_LENGTH })
.withMessage(`Maximum URL length is ${env.MAX_TARGET_LENGTH}.`)
.customSanitizer(addProtocol)
.custom(
value =>
Expand Down
3 changes: 2 additions & 1 deletion server/models/link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Knex } from "knex";
import env from "../env";

export async function createLinkTable(knex: Knex) {
const hasTable = await knex.schema.hasTable("links");
Expand All @@ -24,7 +25,7 @@ export async function createLinkTable(knex: Knex) {
.inTable("domains");
table.string("password");
table.dateTime("expire_in");
table.string("target", 2040).notNullable();
table.string("target", env.MAX_TARGET_LENGTH).notNullable();
table
.integer("user_id")
.references("id")
Expand Down