ReferenceError process is not defined
I am trying to use UploadThing together with a Cloudflare Worker and tiny-request-router. Currently when I send a POST request with a png file attached via Insomnia to my "api/uploadthing" endpoint, I receive the following error "ReferenceError process is not defined". Here is what my "index.ts file looks like:
Here is what my "wrangler.toml" file looks like:
And this is my "types.ts" file:
import { Env, Handler } from './types';
import { Method, Router } from 'tiny-request-router';
import { uploadRouter } from './uploadthing';
import { createServerHandler } from 'uploadthing/server';
import * as process from 'node:process';
const { GET, POST } = createServerHandler({
router: uploadRouter,
});
const router = new Router<Handler>();
router.post('/api/uploadthing', async (req, env) => POST(req));
router.get('/api/uploadthing', async (req) => GET(req));
const worker: ExportedHandler<Env> = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
process.env.UPLOADTHING_APP_ID ??= env.UPLOADTHING_APP_ID;
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';
import * as process from 'node:process';
const { GET, POST } = createServerHandler({
router: uploadRouter,
});
const router = new Router<Handler>();
router.post('/api/uploadthing', async (req, env) => POST(req));
router.get('/api/uploadthing', async (req) => GET(req));
const worker: ExportedHandler<Env> = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
process.env.UPLOADTHING_APP_ID ??= env.UPLOADTHING_APP_ID;
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;Here is what my "wrangler.toml" file looks like:
name = "backend"
main = "src/index.ts"
compatibility_date = "2023-11-21"
compatibility_flags = [ "nodejs_compat" ]
[vars]
API_HOST = "example.com"
API_ACCOUNT_ID = "example_user"
SERVICE_X_DATA = { URL = "service-x-api.dev.example", MY_ID = 123 }name = "backend"
main = "src/index.ts"
compatibility_date = "2023-11-21"
compatibility_flags = [ "nodejs_compat" ]
[vars]
API_HOST = "example.com"
API_ACCOUNT_ID = "example_user"
SERVICE_X_DATA = { URL = "service-x-api.dev.example", MY_ID = 123 }And this is my "types.ts" file:
export interface Env {
UPLOADTHING_SECRET: string;
UPLOADTHING_APP_ID: string;
}
export type Handler = (request: Request, env: Env) => Response | Promise<Response>;export interface Env {
UPLOADTHING_SECRET: string;
UPLOADTHING_APP_ID: string;
}
export type Handler = (request: Request, env: Env) => Response | Promise<Response>;