@hasna/shortlinks 0.1.12 → 0.1.14
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 +152 -191
- package/README.md +21 -18
- package/cloudflare/shortlinks.js +26 -10
- package/cloudflare/wrangler.example.toml +3 -1
- package/dist/cli/index.js +5895 -591
- package/dist/cloudflare.d.ts +1 -0
- package/dist/cloudflare.js +28 -10
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5431 -92
- package/dist/pg-migrate.d.ts +7 -0
- package/dist/pg-store.d.ts +2 -1
- package/dist/remote-storage.d.ts +11 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +4 -0
- package/dist/storage-config.d.ts +37 -0
- package/dist/storage-sync.d.ts +36 -0
- package/dist/storage.d.ts +6 -0
- package/dist/storage.js +5539 -0
- package/infra/aws-ec2-user-data.sh +59 -16
- package/package.json +11 -6
package/dist/cloudflare.d.ts
CHANGED
package/dist/cloudflare.js
CHANGED
|
@@ -56,17 +56,33 @@ function generateWorkerScript() {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const incoming = new URL(request.url);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const proxyTo = (targetOrigin, marker) => {
|
|
60
|
+
const upstream = new URL(incoming.pathname + incoming.search, targetOrigin);
|
|
61
|
+
const headers = new Headers(request.headers);
|
|
62
|
+
headers.set("x-forwarded-host", incoming.host);
|
|
63
|
+
headers.set("x-shortlinks-worker", marker);
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
return fetch(upstream.toString(), {
|
|
66
|
+
method: request.method,
|
|
67
|
+
headers,
|
|
68
|
+
body: request.method === "GET" || request.method === "HEAD" ? undefined : request.body,
|
|
69
|
+
redirect: "manual"
|
|
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");
|
|
70
86
|
}
|
|
71
87
|
};
|
|
72
88
|
`;
|
|
@@ -84,6 +100,8 @@ compatibility_date = "2026-05-01"
|
|
|
84
100
|
|
|
85
101
|
[vars]
|
|
86
102
|
SHORTLINKS_ORIGIN = "${options.origin || "https://shortlinks.example.com"}"
|
|
103
|
+
ATTACHMENTS_ORIGIN = "${options.attachmentsOrigin || ""}"
|
|
104
|
+
SHORTLINKS_RESERVED_PATH_PREFIXES = "a"
|
|
87
105
|
`);
|
|
88
106
|
return { workerPath, wranglerPath };
|
|
89
107
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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";
|
|
4
10
|
export { createShortlinksHandler, serveShortlinks } from "./server.js";
|
|
5
11
|
export { createCloudflarePlan, generateWorkerScript, writeWorkerFiles, upsertCloudflareDnsRecord } from "./cloudflare.js";
|
|
6
12
|
export { createLocalSetupPlan, registerMachinesDns } from "./local.js";
|