INNER CODE UNIT · JavaScript

uploadLimit

aozorae/Edgechat · worker/src/index.js:60

  const uploadLimit = Number(c.env.MAX_FILE_SIZE || 20971520) + 1024 * 1024;
  const maxBytes = ['/api/upload', '/api/v1/uploads'].includes(path) ? uploadLimit : undefined;
  if (requestBodyTooLarge(c.req.raw, maxBytes)) {
    // 提前拒绝超大请求体,避免 Worker 在 JSON 解析前消耗过多内存。
    return errorResponse('请求体过大', 413);
  }

  await next();
});

app.use('/api/*', cors({
  origin: '*',
  allowHeaders: ['Content-Type', 'Authorization'],
  allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
}));

app.get('/api/health', (c) => c.json({ ok: true }));

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…