1.0.0-beta.2 • Published 10 months ago
@arabesque/listener-http v1.0.0-beta.2
HTTP listener for Arabesque
HTTP listener for Arabesque consists of a context type and a factory that returns an Arabesque Listener.
Usage
HTTP
import {createApplication} from "@arabesque/core";
import {createListener} from "@arabesque/listener-http";
import {createServer} from "http";
const listener = createListener(createServer());
const application = createApplication(listener);
application.listen(3000);HTTPS
import {createApplication} from "@arabesque/core";
import {createListener} from "@arabesque/listener-http";
import {createServer} from "https";
import {readFileSync} from "fs";
const listener = createListener(createServer({
key: readFileSync('key.pem'),
cert: readFileSync('cert.pem'),
passphrase: 'passphrase'
}));
const application = createApplication(listener);
application.listen(3000);Using a custom response
import {createApplication} from "@arabesque/core";
import {createListener, ServerResponse} from "@arabesque/listener-http";
import {createServer, IncomingMessage} from "http";
class CustomResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {
public body: string | undefined;
end(cb: () => void) {
return super.end(this.body, cb);
}
}
const listener = createListener<IncomingMessage, CustomResponse>(createServer({
ServerResponse: CustomResponse
}));
const application = createApplication(listener, (context, next) => {
context.response.body = 'foo';
return next(context);
});
application(3000);1.0.0-SNAPSHOT
10 months ago
1.0.0-beta.2
10 months ago
1.0.0-beta.1
1 year ago
0.2.0
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
4 years ago