johnk
johnk
Explore posts from servers
NNuxt
Created by johnk on 9/10/2024 in #❓・help
How would I listen for a websocket message in Nuxt 3, for user initiated notifications to users?
Hello, as the title described, I have a websocket server, and I would like users to send notifications to eachother and listen for notifications. How would I do this? There's not any utilities I can use in a typical nuxt plugin. Thank you!
3 replies
NNuxt
Created by johnk on 8/30/2024 in #❓・help
Type is completely ignored in generated mjs, causes Nuxt #imports issues
Hello, I am using nuxt-open-fetch and all was going well. However it randomly started breaking, and I found out it is because the OpenFetchClient type is completely ignored in the generated .mjs. First, in the nuxt console, I get this error
WARN [nuxt] #imports should be transformed with real imports. There seems to be something wrong with the imports plugin.
WARN [nuxt] #imports should be transformed with real imports. There seems to be something wrong with the imports plugin.
, then in the browser console I get this error
Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/nuxt-open-fetch@0.9.1_magicast@0.3.5_rollup@4.21.1_typescript@5.5.4/node_modules/nuxt-open-fetch/dist/runtime/fetch.mjs?v=ef996c48' does not provide an export named 'OpenFetchClient' (at imports.mjs:31:56)
Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/nuxt-open-fetch@0.9.1_magicast@0.3.5_rollup@4.21.1_typescript@5.5.4/node_modules/nuxt-open-fetch/dist/runtime/fetch.mjs?v=ef996c48' does not provide an export named 'OpenFetchClient' (at imports.mjs:31:56)
. In the server it has the proper export of
export type OpenFetchClient<Paths> = <ReqT extends Extract<keyof Paths, string>, ....
export declare function openFetchRequestInterceptor(...)
export declare function createOpenFetch<Paths>(...)
export declare function fillPath(...)
export type OpenFetchClient<Paths> = <ReqT extends Extract<keyof Paths, string>, ....
export declare function openFetchRequestInterceptor(...)
export declare function createOpenFetch<Paths>(...)
export declare function fillPath(...)
, but in the browser, fetch.mjs has the content of just
export function openFetchRequestInterceptor(ctx) {
ctx.request = fillPath(ctx.request, ctx.options.path);
}
export function createOpenFetch(options, localFetch) {
return (url, opts) => {
opts = typeof options === "function" ? options(opts) : {
...options,
...opts
};
const $fetch = getFetch(url, opts, localFetch);
return $fetch(fillPath(url, opts?.path), opts);
};
}
function getFetch(url, opts, localFetch) {
if (import.meta.server && localFetch) {
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
if (isLocalFetch)
return localFetch;
}
return globalThis.$fetch;
}
export function fillPath(path, params = {}) {
for (const [k, v] of Object.entries(params))
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
return path;
}
export function openFetchRequestInterceptor(ctx) {
ctx.request = fillPath(ctx.request, ctx.options.path);
}
export function createOpenFetch(options, localFetch) {
return (url, opts) => {
opts = typeof options === "function" ? options(opts) : {
...options,
...opts
};
const $fetch = getFetch(url, opts, localFetch);
return $fetch(fillPath(url, opts?.path), opts);
};
}
function getFetch(url, opts, localFetch) {
if (import.meta.server && localFetch) {
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
if (isLocalFetch)
return localFetch;
}
return globalThis.$fetch;
}
export function fillPath(path, params = {}) {
for (const [k, v] of Object.entries(params))
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
return path;
}
What do I do to make sure OpenFetchClient is kept in the generated .mjs?
2 replies
CCoder.com
Created by johnk on 7/23/2024 in #help
Coder docker container works on N4 Google Compute instance but no longer C4
Hello, I have been using coder a ton lately and it's been amazing! I have been using the C4 instance for a few weeks, then recently (within the last few days) used N4 instead. In that time, it appears coder's docker template has become incompatible. To reproduce: 1. Create c4-standard-8 machine 2. Run the following commands 2.a sudo apt install docker.io 2.b sudo usermod -aG docker ${USER} 2.c sudo chmod 666 /var/run/docker.sock 2.d curl -L https://coder.com/install.sh | sh 2.e coder server 3. Open coder, login, and create a workspace using the docker template, you will notice it hangs at docker_image.main: Still creating. forever. if you find the dockerfile and manually run it with docker build . -t test:1 you will see it's an endless loop of this
---> 35a88802559d
Step 2/6 : RUN apt-get update && apt-get install -y curl git golang sudo vim wget && rm -rf /var/lib/apt/lists/*
---> Running in b9f76bfbc76d
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu noble InRelease
Ign:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu noble InRelease
Err:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Connection failed [IP: 91.189.91.81 80]
Ign:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
---> 35a88802559d
Step 2/6 : RUN apt-get update && apt-get install -y curl git golang sudo vim wget && rm -rf /var/lib/apt/lists/*
---> Running in b9f76bfbc76d
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu noble InRelease
Ign:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu noble InRelease
Err:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Connection failed [IP: 91.189.91.81 80]
Ign:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
None of this happens for N4 or others. How do I fix this?
4 replies
PPrisma
Created by johnk on 6/20/2024 in #help-and-questions
Prisma Nuxt RollupError
Hello, I am trying to use @prisma/nuxt, but after installation and when I run npm run dev, it results in the error
ℹ Vite server warmed up in 3864ms 9:33:51 AM
ℹ Vite client warmed up in 5284ms 9:33:52 AM

[9:33:52 AM] WARN [plugin inject] node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts: rollup-plugin-inject: failed to parse /home/joe/novaint/node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts. Consider restricting the plugin to particular files via options.include


[nitro 9:33:52 AM] ERROR RollupError: node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts (2:8): Expected ';', '}' or <eof> (Note that you need plugins to import files that are not JavaScript)


1: import { PrismaClient } from "@prisma/client";
2: declare const prismaClientSingleton: () => PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, i...
^
3: declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client...
4: export type CustomPrismaClient = ReturnType<typeof prismaClientSingleton>;

✔ Nuxt Nitro server built in 2407 ms
ℹ Vite server warmed up in 3864ms 9:33:51 AM
ℹ Vite client warmed up in 5284ms 9:33:52 AM

[9:33:52 AM] WARN [plugin inject] node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts: rollup-plugin-inject: failed to parse /home/joe/novaint/node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts. Consider restricting the plugin to particular files via options.include


[nitro 9:33:52 AM] ERROR RollupError: node_modules/.pnpm/@prisma+nuxt@0.0.30_magicast@0.3.4_nuxt@3.12.2_@opentelemetry+api@1.9.0_@parcel+watcher@2.4.1_2uyq5cr4225ns57lx4llpfiydq/node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts (2:8): Expected ';', '}' or <eof> (Note that you need plugins to import files that are not JavaScript)


1: import { PrismaClient } from "@prisma/client";
2: declare const prismaClientSingleton: () => PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, i...
^
3: declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client...
4: export type CustomPrismaClient = ReturnType<typeof prismaClientSingleton>;

✔ Nuxt Nitro server built in 2407 ms
Does anyone have any ideas?
8 replies
NNuxt
Created by johnk on 4/5/2024 in #❓・help
Set header from server middleware
Hello! I am trying to set the "Authorization" header from server middleware, for an API.
export default defineEventHandler(async (event) => {
const token = await $fetch('https://xxx.kinde.com/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
audience: "https://xxx.kinde.com/api",
grant_type: "client_credentials",
client_id: "xxx",
client_secret: "xxx",
})
}) as { access_token: string };

// I have tried
event.headers.set('authorization', token.access_token);
// I have tried
event.node.req.headers.authorization = token.access_token;
})
export default defineEventHandler(async (event) => {
const token = await $fetch('https://xxx.kinde.com/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
audience: "https://xxx.kinde.com/api",
grant_type: "client_credentials",
client_id: "xxx",
client_secret: "xxx",
})
}) as { access_token: string };

// I have tried
event.headers.set('authorization', token.access_token);
// I have tried
event.node.req.headers.authorization = token.access_token;
})
but nothing seems to be working. I am getting 403 forbidden from my API
const properties = await $fetch(`https://xxx.kinde.com/api/v1/users/${event.context.params?.user}/properties`, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
});
const properties = await $fetch(`https://xxx.kinde.com/api/v1/users/${event.context.params?.user}/properties`, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
});
5 replies