Skip to content
Draft
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
3 changes: 2 additions & 1 deletion ghost/core/core/server/adapters/redirects/FileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import path from 'path';
import RedirectsStoreBase from './RedirectsStoreBase';
import {parseJson, parseYaml} from '../../services/custom-redirects/redirect-config-parser';
import {getBackupRedirectsFilePath} from '../../services/custom-redirects/utils';
import type {RedirectConfig, RedirectsStore} from '../../services/custom-redirects/types';
import type {RedirectConfig} from '../../services/custom-redirects/redirect-config';
import type {RedirectsStore} from '../../services/custom-redirects/redirects-service';

const YAML_FILENAME = 'redirects.yaml';
const JSON_FILENAME = 'redirects.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import * as errors from '@tryghost/errors';
import RedirectsStoreBase from './RedirectsStoreBase';
import {parseJson} from '../../services/custom-redirects/redirect-config-parser';
import {getBackupRedirectsFilePath} from '../../services/custom-redirects/utils';
import type {RedirectConfig, RedirectsStore} from '../../services/custom-redirects/types';
import type {RedirectConfig} from '../../services/custom-redirects/redirect-config';
import type {RedirectsStore} from '../../services/custom-redirects/redirects-service';

const DEFAULT_FILENAME = 'redirects.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import yaml from 'js-yaml';
import tpl from '@tryghost/tpl';
import * as errors from '@tryghost/errors';

import type {RedirectConfig} from './types';
import type {RedirectConfig} from './redirect-config';

const messages = {
jsonParse: 'Could not parse JSON: {context}.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface RedirectConfig {
from: string;
/** Capture groups from `from` can be referenced as `$1`, `$2`, etc. */
to: string;
/** `true` → HTTP 301, otherwise HTTP 302. */
permanent?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import tpl from '@tryghost/tpl';
import * as errors from '@tryghost/errors';

import DynamicRedirectManager from '../lib/dynamic-redirect-manager';
import type {RedirectConfig, RedirectsStore} from './types';
import type {RedirectConfig} from './redirect-config';

/**
* Concurrent `replaceAll` calls have no ordering guarantee — serialize
* externally if that matters.
*/
export interface RedirectsStore {
getAll(): Promise<RedirectConfig[]>;
replaceAll(redirects: RedirectConfig[]): Promise<void>;
}

const messages = {
redirectsRegister: 'Could not register custom redirects.',
Expand Down
16 changes: 0 additions & 16 deletions ghost/core/core/server/services/custom-redirects/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const messages = {
* non-empty `from` / `to` strings, with `from` compilable as a RegExp.
* Throws on the first failure rather than collecting errors.
*
* @param {import('./types').RedirectConfig[]} redirects
* @param {import('./redirect-config').RedirectConfig[]} redirects
*/
const validate = (redirects) => {
if (!_.isArray(redirects)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {RedirectConfig, RedirectsStore} from '../../../../../../core/server/services/custom-redirects/types';
import type {RedirectConfig} from '../../../../../../core/server/services/custom-redirects/redirect-config';
import type {RedirectsStore} from '../../../../../../core/server/services/custom-redirects/redirects-service';

export class InMemoryStore implements RedirectsStore {
private redirects: RedirectConfig[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';

import type {RedirectsStore} from '../../../../../../core/server/services/custom-redirects/types';
import type {RedirectsStore} from '../../../../../../core/server/services/custom-redirects/redirects-service';

interface ContractOptions {
createStore: () => RedirectsStore | Promise<RedirectsStore>;
Expand Down
Loading