Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rest/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export namespace RestBindings {
export const CONFIG = `${CoreBindings.APPLICATION_CONFIG}#rest`;
export const HOST = 'rest.host';
export const PORT = 'rest.port';
export const BASE_PATH = 'rest.basePath';
export const HANDLER = 'rest.handler';

export const API_SPEC = 'rest.apiSpec';
Expand Down
5 changes: 5 additions & 0 deletions packages/rest/src/rest-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ export class RestServer extends Context implements Server {
// Set it to '' so that the http server will listen on all interfaces
options.host = undefined;
}
if (!options.basePath) {
options.basePath = '/';
}
this.bind(RestBindings.PORT).to(options.port);
this.bind(RestBindings.HOST).to(options.host);
this.bind(RestBindings.BASE_PATH).to(options.basePath);
this.api(createEmptyApiSpec());

this.sequence(options.sequence ? options.sequence : DefaultSequence);
Expand Down Expand Up @@ -595,6 +599,7 @@ export class RestServer extends Context implements Server {
export interface RestServerConfig {
host?: string;
port?: number;
basePath?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any code to use server-level basePath? Is it to be implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be a part of a subsequent commit in this PR, but it'll need to wait until @jannyHou lands #916

apiExplorerUrl?: string;
sequence?: Constructor<SequenceHandler>;
}
8 changes: 8 additions & 0 deletions packages/rest/test/unit/rest-server/rest-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
InvokeMethod,
RestBindings,
RestComponent,
RestApplication,
} from '../../..';

describe('RestServer', () => {
Expand Down Expand Up @@ -98,6 +99,13 @@ describe('RestServer', () => {
expect(server.getSync(RestBindings.PORT)).to.equal(4000);
expect(server.getSync(RestBindings.HOST)).to.equal('my-host');
});

it('uses default basePath of "/"', async () => {
const app = new RestApplication();
const server = await app.getServer(RestServer);
const basePath = await server.get(RestBindings.BASE_PATH);
expect(basePath).to.equal('/');
});
});

async function givenRequestContext() {
Expand Down