coldcat
coldcat
CDCloudflare Developers
Created by coldcat on 4/17/2024 in #workers-help
Is it possible to migrate an exisitng Parse Server project to Cloudflare workers?
Hi! I am new to Cloudflare workers and pages. I am wondering is it possible to use Cloudflare workers to replace my Parse Server backend? I think the cloud functions of Parse Server can be migrated to serverless functions since they are triggered by HTTP requests, but I do not know how to achieve it, and failed to find a tutorial about this as well. I even failed to achieve the first step to initialize Parse Server. My code (index.ts) is like:
import Parse from 'parse';
import { ParseServer } from 'parse-server';

const config = {
databaseURI: 'MY_MONGO_URI',
cloud: './cloud/main.js',
appId: 'MY_APP',
masterKey: 'MY_KEY',
serverURL: 'MY_URL',
sessionLength: 1296000,
};
const parseServer = new ParseServer(config);

export default {
async fetch(request: Request, env: any, ctx: any) {
...
},
};
import Parse from 'parse';
import { ParseServer } from 'parse-server';

const config = {
databaseURI: 'MY_MONGO_URI',
cloud: './cloud/main.js',
appId: 'MY_APP',
masterKey: 'MY_KEY',
serverURL: 'MY_URL',
sessionLength: 1296000,
};
const parseServer = new ParseServer(config);

export default {
async fetch(request: Request, env: any, ctx: any) {
...
},
};
But wrangler dev throws:
✘ [ERROR] service core:user:hello-world: Uncaught Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler. https://developers.cloudflare.com/workers/runtime-apis/handlers/
✘ [ERROR] service core:user:hello-world: Uncaught Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler. https://developers.cloudflare.com/workers/runtime-apis/handlers/
However, I have tried moving the new ParseServer(...) line to the handler scope, and it can not fix this error. Can anyone help with this? Thanks in advance!
1 replies