How to use the @phenyl/http-rules.ServerLogic function in @phenyl/http-rules

To help you get started, we’ve selected a few @phenyl/http-rules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phenyl / phenyl / modules / express / src / index.ts View on Github external
return async (req: Request, res: Response, next: NextFunction) => {
      const { path, method, query, headers, body } = req;
      if (!pathRegex.test(path)) {
        return next();
      }
      if (
        method !== "GET" &&
        method !== "POST" &&
        method !== "PUT" &&
        method !== "DELETE"
      ) {
        return next();
      }
      const serverLogic = new ServerLogic(serverParams);
      const encodedHttpRequest: EncodedHttpRequest = {
        method,
        headers: headers as EncodedHttpRequest["headers"],
        path,
        qsParams: query
      };
      if (!body) {
        encodedHttpRequest.body = await getRawBody(req, true);
      } else if (typeof body === "object") {
        encodedHttpRequest.parsedBody = body;
      } else {
        encodedHttpRequest.body = body;
      }

      const response = await serverLogic.handleRequest(encodedHttpRequest);
      res
github phenyl / phenyl / modules / lambda-adapter / src / index.ts View on Github external
return async (
    event: LambdaEvent,
    context: LambdaContext,
    cb: LambdaCallback
  ): Promise => {
    /**
     * Universal server logic.
     * Offers the flow: EncodedHttpRequest => EncodedHttpResponse
     */
    const logic = new ServerLogic(params);

    const encodedHttpRequest = {
      method: event.httpMethod,
      path: event.path,
      body: event.body,
      headers: event.headers,
      qsParams: event.queryStringParameters
    };
    const encodedHttpResponse = await logic.handleRequest(encodedHttpRequest);

    cb(null, encodedHttpResponse);
  };
};
github phenyl / phenyl / modules / http-server / src / index.ts View on Github external
constructor(server: http.Server | https.Server, params: GeneralServerParams) {
    this.server = server;
    this.logic = new ServerLogic(params);
  }
  /**

@phenyl/http-rules

(Almost internal) Set of rules that translates HTTP Request/Response into Phenyl RequestData/ResponseData.

Apache-2.0
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Similar packages