Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (
ctx: InvocationContext,
next: () => ValueOrPromise,
) => {
const httpReq = await ctx.get(RestBindings.Http.REQUEST, {
optional: true,
});
/* istanbul ignore if */
if (!httpReq) {
// Not http request
return next();
}
const key = httpReq.path;
const lang = httpReq.acceptsLanguages(['en', 'zh']) || 'en';
const cachingKey = `${lang}:${key}`;
const cachedResult = await this.cachingService.get(cachingKey);
if (cachedResult) {
debug('Cache found for %s %j', cachingKey, cachedResult);
return cachedResult;
}
const result = await next();
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';
const debug = debugFactory('loopback:v3compat:rest-adapter');
export class Lb3ModelController {
@inject(RestBindings.Http.REQUEST)
protected request: Request;
@inject(RestBindings.Http.RESPONSE)
protected response: Response;
// TODO: a property for strong-remoting's HttpContext
[key: string]: Function | Request | Response;
protected buildMethodArguments(
sharedMethod: SharedMethod,
inputArgs: OperationArgs,
) {
const finalArgs: OperationArgs = [];
for (const argSpec of sharedMethod.accepts) {
const source = argSpec.http && argSpec.http.source;
switch (source) {
case 'req':
finalArgs.push(this.request);
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';
const debug = debugFactory('loopback:v3compat:rest-adapter');
export class Lb3ModelController {
@inject(RestBindings.Http.REQUEST)
protected request: Request;
@inject(RestBindings.Http.RESPONSE)
protected response: Response;
// TODO: a property for strong-remoting's HttpContext
[key: string]: Function | Request | Response;
protected buildMethodArguments(
sharedMethod: SharedMethod,
inputArgs: OperationArgs,
) {
const finalArgs: OperationArgs = [];
for (const argSpec of sharedMethod.accepts) {
const source = argSpec.http && argSpec.http.source;
constructor(
@inject(RestBindings.Http.CONTEXT) public ctx: Context,
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
) {}
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { }
constructor(
@inject(PackageKey) private pkg: PackageInfo,
@inject(RestBindings.Http.RESPONSE) private response: Response,
) {
const html = fs.readFileSync(
path.join(__dirname, '../../../public/index.html.template'),
'utf-8',
);
this.render = template(html);
}
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) {}
constructor(
@inject(RestBindings.CONFIG, {optional: true})
restConfig: RestServerConfig = {},
@inject(RestExplorerBindings.CONFIG, {optional: true})
explorerConfig: RestExplorerConfig = {},
@inject(RestBindings.BASE_PATH) private serverBasePath: string,
@inject(RestBindings.SERVER) private restServer: RestServer,
@inject(RestBindings.Http.CONTEXT) private requestContext: RequestContext,
) {
this.useSelfHostedSpec = explorerConfig.useSelfHostedSpec !== false;
this.openApiSpecUrl = this.getOpenApiSpecUrl(restConfig);
}
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { }
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) {}