Skip to content

Commit

Permalink
Release (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Feb 8, 2023
2 parents 8d39a92 + 6fd5116 commit badbdd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/resources/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ describe('Api', () => {
["get", "post", "delete", "patch", "put", "options"].forEach(method => {
describe(`when creating a new ${method} handler`, () => {
beforeAll(async () => {
await api("main")[method]("/test/", mockFn, {
await api("main1", {
path: "v1",
})[method]("/test/", mockFn, {
security: {
"test": [],
},
Expand All @@ -73,7 +75,7 @@ describe('Api', () => {
});

it("should provide Faas with ApiWorkerOptions", () => {
const expectedOpts = new ApiWorkerOptions("main", "/test/", [method.toUpperCase() as any], {
const expectedOpts = new ApiWorkerOptions("main1", "/v1/test/", [method.toUpperCase() as any], {
security: { "test": [] }
});
expect(faas.Faas).toBeCalledWith(expectedOpts)
Expand Down
8 changes: 5 additions & 3 deletions src/resources/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { fromGrpcError } from '../api/errors';
import resourceClient from './client';
import { HttpMethod } from '../types';
import { make, newer, Resource as Base } from './common';
import path from "path"

export class ApiWorkerOptions{
public readonly api: string;
Expand Down Expand Up @@ -219,8 +220,8 @@ class Api<SecurityDefs extends string> extends Base<ApiDetails> {
constructor(name: string, options: ApiOpts<SecurityDefs> = {}) {
super(name);
const { middleware, path = '/', securityDefinitions = null, security = {} as Record<SecurityDefs, string[]> } = options;
// this.name = name;
this.path = path;
// prepend / to path if its not there
this.path = path.replace(/^\/?/, '/');
this.middleware = Array.isArray(middleware) ? middleware : [middleware];
this.securityDefinitions = securityDefinitions;
this.security = security;
Expand All @@ -245,7 +246,8 @@ class Api<SecurityDefs extends string> extends Base<ApiDetails> {
* @returns the route object, which can be used to register method handlers
*/
route(match: string, options?: RouteOpts): Route<SecurityDefs> {
const r = new Route(this, match, options);
const apiRoute = path.join(this.path, match);
const r = new Route(this, apiRoute, options);
this.routes.push(r);
return r;
}
Expand Down

0 comments on commit badbdd6

Please sign in to comment.