diff --git a/deno/index.js b/deno/index.js index 12c28a7..61718ed 100644 --- a/deno/index.js +++ b/deno/index.js @@ -1,6 +1,5 @@ import { Application, Status } from "@oak/oak"; - -import { corsHeaders, host, port } from "./config.js"; +import { corsHeaders } from "./config.js"; // удаляем host, port из импорта import mainRouter from "./routes/index.js"; const app = new Application(); @@ -10,16 +9,17 @@ app.use(async (ctx, next) => { for (const corsHeaderKey of Object.keys(corsHeaders)) { ctx.response.headers.set(corsHeaderKey, corsHeaders[corsHeaderKey]); } - if (ctx.request.method === "OPTIONS") { ctx.response.status = Status.NoContent; return; } - await next(); }); app.use(mainRouter.routes()); -console.log(`🐿️ Oak is running at ${host}:${port}`); -await app.listen({ host, port }); +// Главная фишка — получение порта из ENV: +const PORT = Deno.env.get("PORT") || "8080"; +// Можно явно указать, что слушаем на всех интерфейсах: +console.log(`🐿️ Oak is running at 0.0.0.0:${PORT}`); +await app.listen({ hostname: "0.0.0.0", port: Number(PORT) }); diff --git a/deno/routes/index.js b/deno/routes/index.js index 4407ecb..aaaf6b8 100644 --- a/deno/routes/index.js +++ b/deno/routes/index.js @@ -1,10 +1,10 @@ import { Router } from "@oak/oak"; - import videoTranslationRouter from "./videoTranslation.js"; import videoSubtitlesRouter from "./videoSubtitles.js"; import streamTranslationRouter from "./streamTranslation.js"; import sessionRouter from "./session.js"; import healthRouter from "./health.js"; +import ttsRouter from "./tts.js"; const mainRouter = new Router() .use( @@ -23,6 +23,7 @@ const mainRouter = new Router() streamTranslationRouter.allowedMethods() ) .use("/session", sessionRouter.routes(), sessionRouter.allowedMethods()) - .use("/health", healthRouter.routes(), healthRouter.allowedMethods()); + .use("/health", healthRouter.routes(), healthRouter.allowedMethods()) + .use("/api/tts", ttsRouter.routes(), ttsRouter.allowedMethods()); export default mainRouter; diff --git a/deno/routes/tts.js b/deno/routes/tts.js new file mode 100644 index 0000000..4b33899 --- /dev/null +++ b/deno/routes/tts.js @@ -0,0 +1,13 @@ +import { Router } from "@oak/oak"; +const ttsRouter = new Router(); + +ttsRouter.post("/", async (ctx) => { + const body = await ctx.request.body.value; // <-- важная строка! + ctx.response.body = { + ok: true, + received: body, + message: "vot-worker принимает POST /api/tts!" + }; +}); + +export default ttsRouter;