@llm-translate/cli 1.0.0-next.4 → 1.0.0-next.5
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/dist/cli/index.js +16 -4
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/serve.ts +14 -3
- package/src/server/index.ts +15 -2
- package/src/server/types.ts +1 -0
package/dist/cli/index.js
CHANGED
|
@@ -4758,8 +4758,9 @@ function createApp(options) {
|
|
|
4758
4758
|
json: options.jsonLogging ?? false
|
|
4759
4759
|
}));
|
|
4760
4760
|
if (options.enableCors) {
|
|
4761
|
+
const corsOrigin = options.corsOrigins ?? "*";
|
|
4761
4762
|
app.use("*", cors({
|
|
4762
|
-
origin:
|
|
4763
|
+
origin: corsOrigin,
|
|
4763
4764
|
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
4764
4765
|
allowHeaders: ["Content-Type", "Authorization", "X-API-Key"],
|
|
4765
4766
|
exposeHeaders: ["X-Request-Id"],
|
|
@@ -4819,7 +4820,12 @@ llm-translate server started`);
|
|
|
4819
4820
|
console.log(` - Health: http://${options.host}:${options.port}/health`);
|
|
4820
4821
|
console.log(` - Translate: http://${options.host}:${options.port}/translate`);
|
|
4821
4822
|
console.log(` - Auth: ${options.enableAuth ? "enabled" : "disabled"}`);
|
|
4822
|
-
|
|
4823
|
+
if (options.enableCors) {
|
|
4824
|
+
const corsInfo = options.corsOrigins ? Array.isArray(options.corsOrigins) ? options.corsOrigins.join(", ") : options.corsOrigins : "all origins";
|
|
4825
|
+
console.log(` - CORS: enabled (${corsInfo})`);
|
|
4826
|
+
} else {
|
|
4827
|
+
console.log(` - CORS: disabled`);
|
|
4828
|
+
}
|
|
4823
4829
|
console.log(` - Cache: ${options.cachePath ?? "disabled"}`);
|
|
4824
4830
|
console.log("");
|
|
4825
4831
|
const shutdown = (signal) => {
|
|
@@ -4848,7 +4854,7 @@ var serveCommand = new Command("serve").description("Start the translation API s
|
|
|
4848
4854
|
"-p, --port <number>",
|
|
4849
4855
|
"Server port (env: TRANSLATE_PORT)",
|
|
4850
4856
|
process.env["TRANSLATE_PORT"] ?? "3000"
|
|
4851
|
-
).option("-H, --host <string>", "Host to bind", "0.0.0.0").option("--no-auth", "Disable API key authentication").option("--cors", "Enable CORS
|
|
4857
|
+
).option("-H, --host <string>", "Host to bind", "0.0.0.0").option("--no-auth", "Disable API key authentication").option("--cors [origins]", "Enable CORS (optionally specify allowed origins, comma-separated)").option("--json", "Use JSON logging format (for containers)").option(
|
|
4852
4858
|
"--cache-dir <path>",
|
|
4853
4859
|
"Cache directory path (env: TRANSLATE_CACHE_DIR)",
|
|
4854
4860
|
process.env["TRANSLATE_CACHE_DIR"]
|
|
@@ -4868,11 +4874,17 @@ var serveCommand = new Command("serve").description("Start the translation API s
|
|
|
4868
4874
|
"Set TRANSLATE_API_KEY environment variable to enable authentication.\n"
|
|
4869
4875
|
);
|
|
4870
4876
|
}
|
|
4877
|
+
const enableCors = options.cors !== void 0 && options.cors !== false;
|
|
4878
|
+
let corsOrigins;
|
|
4879
|
+
if (typeof options.cors === "string") {
|
|
4880
|
+
corsOrigins = options.cors.includes(",") ? options.cors.split(",").map((o) => o.trim()) : options.cors;
|
|
4881
|
+
}
|
|
4871
4882
|
startServer({
|
|
4872
4883
|
port,
|
|
4873
4884
|
host,
|
|
4874
4885
|
enableAuth,
|
|
4875
|
-
enableCors
|
|
4886
|
+
enableCors,
|
|
4887
|
+
corsOrigins,
|
|
4876
4888
|
apiKey: process.env["TRANSLATE_API_KEY"],
|
|
4877
4889
|
jsonLogging: options.json ?? false,
|
|
4878
4890
|
cachePath: options.cacheDir
|