SkepticMystic
SkepticMystic
DDeno
Created by SkepticMystic on 9/5/2024 in #help
How to only load worker once
I have a file that initialises a worker, and exports a function that posts a message to that worker. But if I import that function into multiple other files, the worker gets loaded each time. How can I prevent this to ensure only one instance of the worker is loaded, regardless of how many files I use the function in?
2 replies
DDeno
Created by SkepticMystic on 2/1/2023 in #help
docker compose up of Oak server throws: SyntaxError: Duplicate export of 'type'
I am just learning how to use Docker, and am trying to put up a container of an Oak server. When running docker compose up, it throws the error mentioned above. This doesn't happen locally, or on Deno Deploy. I'm not really sure where to start? Can I somehow ignore this error, or is it actually a problem? My docker-compose.yml is:
version: "3"

services:
web:
build: .
container_name: server
image: deno-image
ports:
- "8000:8000"
version: "3"

services:
web:
build: .
container_name: server
image: deno-image
ports:
- "8000:8000"
And Dockerfile:
FROM denoland/deno:1.10.3

EXPOSE 8000

WORKDIR /app

USER deno

ADD . /app

RUN deno cache --no-check src/index.ts

CMD ["run", "--allow-net", "--allow-read", "--allow-env", "--no-check", "src/index.ts"]
FROM denoland/deno:1.10.3

EXPOSE 8000

WORKDIR /app

USER deno

ADD . /app

RUN deno cache --no-check src/index.ts

CMD ["run", "--allow-net", "--allow-read", "--allow-env", "--no-check", "src/index.ts"]
The full error is:
server | error: Uncaught SyntaxError: Duplicate export of 'type'
server | export { type NativeRequest } from "./http_server_native_request.ts";
server | ~~~~
server | at <anonymous> (https://deno.land/x/oak@v11.1.0/mod.ts:93:10)
server | error: Uncaught SyntaxError: Duplicate export of 'type'
server | export { type NativeRequest } from "./http_server_native_request.ts";
server | ~~~~
server | at <anonymous> (https://deno.land/x/oak@v11.1.0/mod.ts:93:10)
Any help would be greatly appreciated, thank you
2 replies
DDeno
Created by SkepticMystic on 11/29/2022 in #help
Is there an event that triggers when an Oak Deploy instance is closing?
I cannot find anything in the Deploy docs, specifically. But I see that the Oak app runs a callback when the server closes. Something like this should work, I think:
app.listen({ port: 8080 }).then(() => {
console.log('Shutting down...');
db.collection('test').insertOne({ createdAt: new Date() })
});
app.listen({ port: 8080 }).then(() => {
console.log('Shutting down...');
db.collection('test').insertOne({ createdAt: new Date() })
});
But the console log doesn't run. Maybe the way Deploy closes instances doesn't allow for this? Any advice would be really helpful
1 replies
DDeno
Created by SkepticMystic on 10/17/2022 in #help
Silence error logs on Oak server
I'm trying to silence specific errors on an Oak server on Deploy. A Github issue said to add an 'error' event listener to the app. I did the following, but the error is still logged. Am I missing something?
app.addEventListener('error', (e) => {
const lowerMsg = e.error?.message?.toLowerCase();
if (lowerMsg?.includes('early eof')) { return }
console.error(e.error);
})
app.addEventListener('error', (e) => {
const lowerMsg = e.error?.message?.toLowerCase();
if (lowerMsg?.includes('early eof')) { return }
console.error(e.error);
})
5 replies