@hasna/shortlinks 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -152
- package/README.md +18 -21
- package/cloudflare/shortlinks.js +10 -26
- package/cloudflare/wrangler.example.toml +1 -3
- package/dist/cli/index.js +566 -6261
- package/dist/cloudflare.d.ts +0 -1
- package/dist/cloudflare.js +10 -28
- package/dist/config.d.ts +0 -8
- package/dist/index.d.ts +1 -8
- package/dist/index.js +202 -5889
- package/dist/pg-store.d.ts +1 -3
- package/dist/server.d.ts +1 -18
- package/dist/server.js +22 -183
- package/dist/store.d.ts +0 -1
- package/dist/types.d.ts +0 -3
- package/infra/aws-ec2-user-data.sh +16 -65
- package/package.json +6 -11
- package/dist/api-client.d.ts +0 -30
- package/dist/pg-migrate.d.ts +0 -7
- package/dist/remote-storage.d.ts +0 -11
- package/dist/storage-config.d.ts +0 -37
- package/dist/storage-sync.d.ts +0 -36
- package/dist/storage.d.ts +0 -6
- package/dist/storage.js +0 -5561
package/dist/cloudflare.d.ts
CHANGED
package/dist/cloudflare.js
CHANGED
|
@@ -56,33 +56,17 @@ function generateWorkerScript() {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const incoming = new URL(request.url);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
headers.set("x-shortlinks-worker", marker);
|
|
59
|
+
const upstream = new URL(incoming.pathname + incoming.search, origin);
|
|
60
|
+
const headers = new Headers(request.headers);
|
|
61
|
+
headers.set("x-forwarded-host", incoming.host);
|
|
62
|
+
headers.set("x-shortlinks-worker", "cloudflare");
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const reserved = (env.SHORTLINKS_RESERVED_PATH_PREFIXES || "a")
|
|
74
|
-
.split(",")
|
|
75
|
-
.map((value) => value.trim().toLowerCase())
|
|
76
|
-
.filter(Boolean);
|
|
77
|
-
const firstSegment = decodeURIComponent(incoming.pathname.replace(/^\\/+/, "").split("/")[0] || "").toLowerCase();
|
|
78
|
-
if (firstSegment && reserved.includes(firstSegment)) {
|
|
79
|
-
if (env.ATTACHMENTS_ORIGIN) {
|
|
80
|
-
return proxyTo(env.ATTACHMENTS_ORIGIN, "attachments");
|
|
81
|
-
}
|
|
82
|
-
return new Response("Reserved path prefix", { status: 404 });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return proxyTo(origin, "cloudflare");
|
|
64
|
+
return fetch(upstream.toString(), {
|
|
65
|
+
method: request.method,
|
|
66
|
+
headers,
|
|
67
|
+
body: request.method === "GET" || request.method === "HEAD" ? undefined : request.body,
|
|
68
|
+
redirect: "manual"
|
|
69
|
+
});
|
|
86
70
|
}
|
|
87
71
|
};
|
|
88
72
|
`;
|
|
@@ -100,8 +84,6 @@ compatibility_date = "2026-05-01"
|
|
|
100
84
|
|
|
101
85
|
[vars]
|
|
102
86
|
SHORTLINKS_ORIGIN = "${options.origin || "https://shortlinks.example.com"}"
|
|
103
|
-
ATTACHMENTS_ORIGIN = "${options.attachmentsOrigin || ""}"
|
|
104
|
-
SHORTLINKS_RESERVED_PATH_PREFIXES = "a"
|
|
105
87
|
`);
|
|
106
88
|
return { workerPath, wranglerPath };
|
|
107
89
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -3,12 +3,6 @@ export declare const DEFAULT_DATA_DIR: string;
|
|
|
3
3
|
export interface ShortlinksConfig {
|
|
4
4
|
defaultDomain?: string;
|
|
5
5
|
publicBaseUrl?: string;
|
|
6
|
-
mode?: "local" | "remote" | "api";
|
|
7
|
-
api?: {
|
|
8
|
-
baseUrl?: string;
|
|
9
|
-
token?: string;
|
|
10
|
-
tokenEnv?: string;
|
|
11
|
-
};
|
|
12
6
|
cloudflare?: {
|
|
13
7
|
accountId?: string;
|
|
14
8
|
workerName?: string;
|
|
@@ -22,7 +16,5 @@ export declare function getDatabasePath(explicitPath?: string): string;
|
|
|
22
16
|
export declare function loadConfig(): ShortlinksConfig;
|
|
23
17
|
export declare function saveConfig(config: ShortlinksConfig): void;
|
|
24
18
|
export declare function updateConfig(patch: ShortlinksConfig): ShortlinksConfig;
|
|
25
|
-
export declare function getApiBaseUrl(config?: ShortlinksConfig): string | null;
|
|
26
|
-
export declare function getApiToken(config?: ShortlinksConfig): string | null;
|
|
27
19
|
export declare function normalizeHostname(input: string): string;
|
|
28
20
|
export declare function formatShortUrl(hostname: string, slug: string, publicBaseUrl?: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
export { ShortlinksDatabase, SQLITE_MIGRATIONS, makeId, now } from "./database.js";
|
|
2
2
|
export { ShortlinksStore } from "./store.js";
|
|
3
3
|
export { PgShortlinksStore } from "./pg-store.js";
|
|
4
|
-
export { CANONICAL_SHORTLINKS_RDS_CLUSTER, CANONICAL_SHORTLINKS_RDS_DATABASE, CANONICAL_SHORTLINKS_RDS_SECRET_PATH, SHORTLINKS_STORAGE_ENV, SHORTLINKS_STORAGE_FALLBACK_ENV, SHORTLINKS_STORAGE_MODE_ENV, SHORTLINKS_STORAGE_MODE_FALLBACK_ENV, STORAGE_DATABASE_ENV, STORAGE_MODE_ENV, getConnectionString, getCanonicalShortlinksRdsConfig, getStorageDatabaseEnv, getStorageDatabaseEnvName, getStorageConfig, getStorageConnectionString, getStorageDatabaseUrl, } from "./storage-config.js";
|
|
5
|
-
export type { CanonicalShortlinksRdsConfig, StorageConfig, StorageEnv, StorageMode } from "./storage-config.js";
|
|
6
|
-
export { PgAdapterAsync } from "./remote-storage.js";
|
|
7
|
-
export { applyPgMigrations } from "./pg-migrate.js";
|
|
8
|
-
export { SHORTLINKS_STORAGE_TABLES, STORAGE_TABLES, getStoragePg, getStorageStatus, parseStorageTables, pullStorageChanges, pushStorageChanges, runStorageMigrations, syncStorageChanges, } from "./storage-sync.js";
|
|
9
|
-
export type { StorageStatus, StorageSyncResult, SyncResult } from "./storage-sync.js";
|
|
10
4
|
export { createShortlinksHandler, serveShortlinks } from "./server.js";
|
|
11
|
-
export { ShortlinksApiClient } from "./api-client.js";
|
|
12
5
|
export { createCloudflarePlan, generateWorkerScript, writeWorkerFiles, upsertCloudflareDnsRecord } from "./cloudflare.js";
|
|
13
6
|
export { createLocalSetupPlan, registerMachinesDns } from "./local.js";
|
|
14
7
|
export { PG_MIGRATIONS } from "./pg-migrations.js";
|
|
15
|
-
export { formatShortUrl,
|
|
8
|
+
export { formatShortUrl, getConfigPath, getDataDir, getDatabasePath, loadConfig, normalizeHostname, saveConfig } from "./config.js";
|
|
16
9
|
export { normalizeSlug, randomToken } from "./slug.js";
|
|
17
10
|
export type { AddDomainInput, Click, ClickInput, CreateLinkInput, Domain, Link, LinkStats } from "./types.js";
|