kristiankauffeld
kristiankauffeld
Explore posts from servers
CDCloudflare Developers
Created by kristiankauffeld on 12/27/2023 in #workers-help
Fetch Request Returns 'Undefined' during File Upload Polling Process"
Here is a screenshot of the browser console logs which shows that since the polling doesn't return a response and it attempts to receive a respone a maximum number of 21 times. At the end the upload process actually completes. The retry mechanism is defined here: https://github.com/pingdotgg/uploadthing/blob/60d3ccfbe312775fd1c2156fcc362862eac843cb/packages/shared/src/utils.ts#L136-L161
2 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/19/2023 in #workers-help
Your worker created multiple branches of a single stream (for instance, by calling response.clone()
the only other place I can find a usage of clone is here, but the warning is thrown before this is reached: https://github.com/pingdotgg/uploadthing/blob/ea0f3c96f5db2fa945592d5efc06bf84811c5525/packages/uploadthing/src/sdk/utils.ts#L85
5 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/19/2023 in #workers-help
Your worker created multiple branches of a single stream (for instance, by calling response.clone()
@kian it throws the warning even though I commented the cloning part out:
export async function safeParseJSON<T>(
input: string | ResponseEsque | RequestLike,
): Promise<T | Error> {
if (typeof input === "string") {
try {
return JSON.parse(input) as T;
} catch (err) {
console.error(`Error parsing JSON, got '${input}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}

//const clonedRes = input.clone?.();
try {
return (await input.json()) as T;
} catch (err) {
//const text = (await input?.text()) ?? "unknown";
//const text = await input?.text()) ?? "unknown";
//console.error(`Error parsing JSON, got '${text}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}
export async function safeParseJSON<T>(
input: string | ResponseEsque | RequestLike,
): Promise<T | Error> {
if (typeof input === "string") {
try {
return JSON.parse(input) as T;
} catch (err) {
console.error(`Error parsing JSON, got '${input}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}

//const clonedRes = input.clone?.();
try {
return (await input.json()) as T;
} catch (err) {
//const text = (await input?.text()) ?? "unknown";
//const text = await input?.text()) ?? "unknown";
//console.error(`Error parsing JSON, got '${text}'`);
return new Error(`Error parsing JSON, got '${input}'`);
}
}
5 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/7/2023 in #workers-help
ReferenceError process is not defined
@kian thanks for your help I have solved it now!
10 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/7/2023 in #workers-help
ReferenceError process is not defined
If I do it like this, then I won't get the "ReferenceError: process is not defined" error anymore, but instead I get a "400 bad request" and this JSON response: { "message": "No slug provided" }
import { Env, Handler } from './types';
import { Method, Router } from 'tiny-request-router';
import { uploadRouter } from './uploadthing';
import { createServerHandler } from 'uploadthing/server';

const router = new Router<Handler>();

router.post('/api/uploadthing', async (req, env) => {
const { GET, POST } = createServerHandler({
router: uploadRouter,
config: {
uploadthingId: env.UPLOADTHING_APP_ID,
uploadthingSecret: env.UPLOADTHING_SECRET,
callbackUrl: 'http://localhost:8787/api/uploadthing',
},
});
return POST(req);
});

router.get('/api/uploadthing', async (req) => GET(req));

const worker: ExportedHandler<Env> = {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const match = router.match(request.method as Method, url.pathname);

if (!match) return new Response('Not found', { status: 404 });

return match.handler(request, env);
},
};

export default worker;
import { Env, Handler } from './types';
import { Method, Router } from 'tiny-request-router';
import { uploadRouter } from './uploadthing';
import { createServerHandler } from 'uploadthing/server';

const router = new Router<Handler>();

router.post('/api/uploadthing', async (req, env) => {
const { GET, POST } = createServerHandler({
router: uploadRouter,
config: {
uploadthingId: env.UPLOADTHING_APP_ID,
uploadthingSecret: env.UPLOADTHING_SECRET,
callbackUrl: 'http://localhost:8787/api/uploadthing',
},
});
return POST(req);
});

router.get('/api/uploadthing', async (req) => GET(req));

const worker: ExportedHandler<Env> = {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const match = router.match(request.method as Method, url.pathname);

if (!match) return new Response('Not found', { status: 404 });

return match.handler(request, env);
},
};

export default worker;
10 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/7/2023 in #workers-help
ReferenceError process is not defined
how and where should I define process?
10 replies