Optional
key: Nilable<ObjectKey>The key. Default: The name of the underlying property.
The new decorator function.
import createServer, { Controller, ControllerBase, GET, IHttpRequest, IHttpResponse, Import } from '@egomobile/http-server'
// setup controller and define the
// value keys to import
@Controller()
export default class MyController extends ControllerBase {
@Import() // s. [1]
public foo!: string
@Import('currentTime') // s. [2]
public now!: Date
@GET()
async index(request: IHttpRequest, response: IHttpResponse) {
response.write(this.foo + ': ' + this.now)
}
}
// setup server with import values ...
const app = createServer()
// setup controller
// with import values
app.controllers(__dirname, {
// [1] no function => static value for MyController.foo property
foo: 'bar',
// [2] function => dynamic value for MyController.now property
currentTime: () => new Date(),
})
app.listen()
Generated using TypeDoc
Imports a value into a property and sets up a getter for this.