Comparing version 0.0.34 to 0.0.35
{ | ||
"name": "webdetta", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"author": "Fedot Kriutchenko <fodyadev@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -13,6 +13,2 @@ import { safe } from '../common/func.js'; | ||
const validatePath = path => { | ||
if (typeof path != 'string') throw Error('Path must be a string'); | ||
} | ||
const collectMethods = (func, methods) => | ||
@@ -48,3 +44,2 @@ new Proxy((...a) => func(methods, ...a), { | ||
wsApi: (path, { pool, onOpen, onClose, ctx, methods }) => { | ||
validatePath(path); | ||
const api = rpcApiWs({ pool, onOpen, onClose, methods }); | ||
@@ -56,17 +51,16 @@ wss.route(path, (req, ws) => ctx.call(api.upgrade(ws), req)); | ||
httpApi: (path, { bodyLimit='50mb', ctx, methods }) => { | ||
validatePath(path); | ||
path = path.replace(/\/$/, '') + '/:name'; | ||
const handlers = []; | ||
if (bodyLimit) handlers.push( | ||
bodyParser.json({limit: bodyLimit}), | ||
bodyParser.urlencoded({limit: bodyLimit, extended: true}) | ||
); | ||
const api = rpcApiHttp(methods); | ||
handlers.push(async (req, res) => { | ||
await ctx.call(req.ctx = {}, req, res); | ||
if (res.headersSent) return; | ||
const r = await api.processCall(req.ctx, req.params.name, req.body); | ||
res.status(r.status).send(r.result); | ||
}); | ||
app.post(path, ...handlers); | ||
app.post(path, ...[ | ||
...(!bodyLimit ? [] : [ | ||
bodyParser.json({limit: bodyLimit}), | ||
bodyParser.urlencoded({limit: bodyLimit, extended: true}) | ||
]), | ||
async (req, res) => { | ||
await ctx.call(req.ctx = {}, req, res); | ||
if (res.headersSent) return; | ||
const r = await api.processCall(req.ctx, req.params.name, req.body); | ||
res.status(r.status).send(r.result); | ||
} | ||
]); | ||
return instance; | ||
@@ -76,3 +70,2 @@ }, | ||
wsHandler: (path, handler) => { | ||
validatePath(path); | ||
wss.route(path, handler); | ||
@@ -83,3 +76,2 @@ return instance; | ||
httpHandler: collectMethods((methods=['all'], path, ...args) => { | ||
validatePath(path); | ||
for (const method of methods) app[method.toLowerCase()](path, ...args); | ||
@@ -90,3 +82,2 @@ return instance; | ||
wsProxy: (path, resolve) => { | ||
validatePath(path); | ||
wss.routeRaw(path, async (req, socket, head) => { | ||
@@ -100,3 +91,2 @@ const opts = await resolveProxyOptions(resolve, req, socket, head) ?? {}; | ||
httpProxy: collectMethods((methods=['all'], path, resolve) => { | ||
validatePath(path); | ||
for (const method of methods) | ||
@@ -110,3 +100,3 @@ app[method.toLowerCase()](path, async (req, res, next) => { | ||
wsSdk: (path, methods) => { | ||
sdk: (path, { methods }) => { | ||
const { handlers, clientCode } = generateSDK(methods); | ||
@@ -127,3 +117,2 @@ instance.httpHandler.get(path, (req, res) => { | ||
static: (path, ...dirs) => { | ||
validatePath(path); | ||
for (const dir of dirs) app.use(path, express.static(dir)); | ||
@@ -134,3 +123,2 @@ return instance; | ||
cors: (path, options) => { | ||
validatePath(path); | ||
app.options(path, cors(options)); | ||
@@ -137,0 +125,0 @@ return instance; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26888
773