1
This commit is contained in:
parent
a03119b692
commit
1c6c3d38fb
16
src/application.ts
Normal file
16
src/application.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {ApplicationConfig} from '@loopback/core';
|
||||
import {RestApplication} from '@loopback/rest';
|
||||
import {RestExplorerBindings} from '@loopback/rest-explorer';
|
||||
import {PingController} from './controllers/ping.controller';
|
||||
|
||||
export class Application extends RestApplication {
|
||||
constructor(options: ApplicationConfig = {}) {
|
||||
super(options);
|
||||
this.projectRoot = __dirname;
|
||||
this.controller(PingController);
|
||||
this.bind(RestExplorerBindings.CONFIG).to({
|
||||
path: '/explorer',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
9
src/controllers/ping.controller.ts
Normal file
9
src/controllers/ping.controller.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import {get} from '@loopback/rest';
|
||||
|
||||
export class PingController {
|
||||
@get('/ping')
|
||||
ping(): object {
|
||||
return {message: 'pong'};
|
||||
}
|
||||
}
|
||||
|
||||
14
src/index.ts
Normal file
14
src/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {Application} from './application';
|
||||
|
||||
export async function main() {
|
||||
const app = new Application();
|
||||
await app.boot();
|
||||
await app.start();
|
||||
console.log(`Application is running at http://127.0.0.1:3000`);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Cannot start the application.', err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
35
src/sequence.ts
Normal file
35
src/sequence.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import {
|
||||
SequenceHandler,
|
||||
FindRoute,
|
||||
ParseParams,
|
||||
InvokeMethod,
|
||||
Send,
|
||||
Reject,
|
||||
RequestContext,
|
||||
} from '@loopback/rest';
|
||||
|
||||
export class MySequence implements SequenceHandler {
|
||||
constructor(
|
||||
public findRoute: FindRoute,
|
||||
public parseParams: ParseParams,
|
||||
public invoke: InvokeMethod,
|
||||
public send: Send,
|
||||
public reject: Reject,
|
||||
) {}
|
||||
|
||||
async handle(context: RequestContext): Promise<void> {
|
||||
const {request, response} = context;
|
||||
try {
|
||||
const route = this.findRoute(request);
|
||||
|
||||
const args = await this.parseParams(request, route);
|
||||
|
||||
const result = await this.invoke(route, args);
|
||||
|
||||
this.send(response, result);
|
||||
} catch (error) {
|
||||
this.reject(context, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user