【发布时间】:2022-09-27 22:05:49
【问题描述】:
所以我写了一个 Twitch 聊天机器人。 Dockerized(docker compose),带 express 的 Node.js v16。
对于我的授权页面,有人可以用来在 Twitch API 上授权我的机器人,我使用了 /auth/request 这样的路由
this.serverUrl = serverUrl;
this.port = port;
this.app = express();
this.app.use(express.static(__dirname + \'/frontend/\'));
//Landingpage to authorize App for channel
this.app.get(\'/auth/request/\', (req:any, res:any) => {
console.log(\'/\');
var indexhtml = new Replacer().replace(__dirname + \'/frontend/auth/request/index.html\', \'%SERVER_URL%\', this.serverUrl);
res.send(indexhtml);
});
(我使用 \'%SERVER_URL%\' 作为占位符,它被我的本地主机或域地址替换。)
第一次,有错误,替换字符串和 twitch API 响应错误,当然。 但在此之后,我无法再改变路线的行为了。此外,它仍然可以完全评论它。
几次重启都没有帮助。即使
docker-compose up --build --force-recreate
我将路线放回原处,修复了错误并将路线更改为 \"/\"。无论如何我都想这样做。在这里它工作正常,但在旧路线上,它仍然可用,但出现替换错误。 我认为某种奇怪的守护程序服务仍在运行,但这不是一回事,因为它在容器未运行时不可用。
我没有更多的想法... 我怎样才能摆脱这条烦人的路线?它不应该再存在了。
码头工人-compose.yml
version: \'0.1\'
services:
node:
container_name: sacrificulus
build: ./app
ports:
- \"3000:3000\"
volumes:
- D:\\Projects\\WebProjects\\AlfredServes\\app:/app/token_store
command: [\"./node_modules/.bin/ts-node\", \"./src/bot.ts\"]
Dockerfile
FROM node:16
WORKDIR /app
COPY . /app
ENV TWITCH_CLIENT_ID=12345mytwitchclientid54321
ENV URL_LIVE=https://bot.example.com
ENV PORT_LIVE=80
ENV URL_LOCAL=http://localhost:
ENV PORT_LOCAL=3000
ENV LIVE_OR_LOCAL=local
#ENV LIVE_OR_LOCAL=live
RUN npm install
有没有人有类似的行为?
(对不起我的代码质量:D)
-
但是... docker-compose 在您更改代码后是否重建了所有内容?您应该在“docker-compose up”的输出中看到这一点。如果是这样,那么你应该没问题。我喜欢在“up”之前做一个明确的“docker-compose down”,只是为了确保旧的被销毁。而且我不会过多贬低您的代码质量,但是在您的 Dockerfile 中只复制 npm 包文件,然后运行 npm 安装,然后复制其余代码会更有效,所以它不会每次小的代码更改后都必须重新运行 npm install 。
标签: node.js typescript docker express docker-compose