Best Performance
For the highest throughput, use these defaults:
- Enable uWebSockets runtime:
uWebSocketsEnabled: true - Disable powered-by header:
poweredByHeader: false - For headers that should be sent on every request (for example CORS-related headers), use
staticResponseHeadersinstead of per-request hooks
Example (production-oriented):
import Oweb from 'owebjs';
const app = await new Oweb({ uWebSocketsEnabled: true, poweredByHeader: false, autoPreflight: true, staticResponseHeaders: { // CORS (set your real origin in production) 'access-control-allow-origin': 'https://yourdomain.com', 'access-control-allow-methods': 'GET,POST,PUT,PATCH,DELETE,OPTIONS', 'access-control-allow-headers': 'Content-Type, Authorization', vary: 'Origin',
// Security headers 'x-content-type-options': 'nosniff', 'x-frame-options': 'DENY', 'referrer-policy': 'strict-origin-when-cross-origin', 'permissions-policy': 'geolocation=(), microphone=(), camera=()', 'cross-origin-opener-policy': 'same-origin', 'cross-origin-resource-policy': 'same-site', },}).setup();
await app.loadRoutes({ directory: 'routes', hmr: { enabled: false, },});
await app.start({ port: 3000, host: '0.0.0.0' });