express#Request TypeScript Examples

The following examples show how to use express#Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: server-utils.ts    From anthem with Apache License 2.0 7 votes vote down vote up
requestLogger = (
  req: Request,
  _: Response,
  next: NextFunction,
) => {
  if (ENV.ENABLE_LOGGING) {
    const { body } = req;
    const { operationName, variables } = body;

    // Don't log introspection query (clutter):
    if (Boolean(operationName) && operationName !== "IntrospectionQuery") {
      console.log(chalk.blue("Request Received:"));
      console.log(
        `- Query: ${operationName}\n- Variables: ${JSON.stringify(
          variables,
        )}\n`,
      );
    }
  }

  return next();
}
Example #2
Source File: resolver.ts    From one-platform with MIT License 6 votes vote down vote up
export default function resolver(
  req: Request,
  res: Response,
  next: NextFunction
): void {
  const { uid, role, rhatUUID } = res.locals.user;

  /* Adding additional roles */
  role.push('user:' + uid, 'user:' + rhatUUID, 'op-users');

  const token = createHmac('sha1', COUCHDB_SECRET as string)
    .update(uid) // lgtm[js/weak-cryptographic-algorithm]
    .digest('hex');

  const proxy = createProxyMiddleware({
    target: COUCHDB_HOST,
    secure: useSecureSSL,
    changeOrigin: true,
    headers: {
      'X-Auth-CouchDB-UserName': uid,
      'X-Auth-CouchDB-Roles': role.join(','),
      'X-Auth-CouchDB-Token': token,
    },
    pathRewrite: {
      ['^/api/couchdb']: '',
    },
  });
  proxy(req, res, next);
}
Example #3
Source File: jwt.strategy.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
constructor(
    private readonly configService: ConfigService,
    private readonly logger: MyLogger,
  ) {
    super({
      jwtFromRequest: ExtractJwt.fromExtractors([
        (req: Request) => {
          return req?.cookies?.w_auth;
        },
      ]),
      ignoreExpiration: false,
      secretOrKey: configService.get('jwt.secret'),
    });
  }
Example #4
Source File: restHandler.ts    From AIPerf with MIT License 6 votes vote down vote up
// TODO add validators for request params, query, body
    private checkStatus(router: Router): void {
        router.get('/check-status', (req: Request, res: Response) => {
            const ds: DataStore = component.get<DataStore>(DataStore);
            ds.init().then(() => {
                res.send(this.nniManager.getStatus());
            }).catch(async (err: Error) => {
                this.handleError(err, res);
                this.log.error(err.message);
                this.log.error(`Datastore initialize failed, stopping rest server...`);
                await this.restServer.stop();
            });
        });
    }
Example #5
Source File: askExpressMiddleware.ts    From askql with MIT License 6 votes vote down vote up
export function askExpressMiddleware(
  environment: AskEnvironment,
  config: AskExpressMiddlewareConfig = {
    callNext: true,
    passError: false,
  }
) {
  return async function (
    request: Request,
    response: Response,
    next: NextFunction
  ) {
    try {
      const parsedCode = getParsedCode(request.body);
      const queryResponse = await runUntyped(environment, parsedCode);
      response.json(queryResponse);

      if (config.callNext) {
        return next();
      }
    } catch (err) {
      config.passError && next(err);
      return;
    }
    return;
  };
}
Example #6
Source File: httpErrorHandler.middleware.ts    From Graphql-api with ISC License 6 votes vote down vote up
function errorMiddleware(
  error: HttpException,
  request: Request,
  response: Response,
  next: NextFunction
): void {
  const status: number = error.status || 500;
  const message: string = error.message || 'Something went wrong';
  response.status(status).send({
    status,
    message
  });
  next({ err: message });
}
Example #7
Source File: functions.ts    From cookietrack-api with MIT License 6 votes vote down vote up
initResponse = (req: Request) => {
  let wallet = req.query.address as Address;
  let response: APIResponse = {
    status: 'ok',
    data: [],
    request: req.originalUrl
  }
  if(wallet != undefined) {
    if(!blacklist.includes(wallet.toLowerCase())) {
      if(!ethers.utils.isAddress(wallet)) {
        response.status = 'error';
        response.data = [{error: 'Invalid Wallet Address'}];
      }
    } else {
      response.status = 'error';
      response.data = [{error: 'Request Spam Detected: Get in touch with us through Discord'}];
    }
  } else {
    response.status = 'error';
    response.data = [{error: 'No Wallet Address in Request'}];
  }
  return response;
}