Wrap missingServerName, update example

This commit is contained in:
Alex Hultman 2020-08-17 05:41:00 +02:00
parent f77d07014a
commit 103a0562be
3 changed files with 37 additions and 9 deletions

View File

@ -7,14 +7,22 @@ const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).addServerName("localhost", {
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).removeServerName("localhost").addServerName("localhost", {
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).missingServerName((hostname) => {
/* Note: You don't have to use this callback but can pre-load
* relevant server names up front. This callback is not "async",
* you either add the server name HERE IMMEDIATELY, or the hangshake
* will continue with default certificate (which will most likely fail) */
console.log("Hello! We are missing server name <" + hostname + ">");
/* We simply assume it is localhost, so adding it here */
app.addServerName("localhost", {
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
});
}).get('/*', (res, req) => {
res.end('Hello World!');
}).listen(port, (token) => {

View File

@ -422,6 +422,25 @@ void uWS_App_removeServerName(const FunctionCallbackInfo<Value> &args) {
args.GetReturnValue().Set(args.Holder());
}
template <typename APP>
void uWS_App_missingServerName(const FunctionCallbackInfo<Value> &args) {
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
Isolate *isolate = args.GetIsolate();
UniquePersistent<Function> missingPf;
missingPf.Reset(args.GetIsolate(), Local<Function>::Cast(args[0]));
app->missingServerName([missingPf = std::move(missingPf), isolate](const char *hostname) {
/* We hand a JavaScript string here */
HandleScope hs(isolate);
Local<Function> missingLf = Local<Function>::New(isolate, missingPf);
Local<Value> argv[1] = {String::NewFromUtf8(isolate, hostname, NewStringType::kNormal).ToLocalChecked()};
CallJS(isolate, missingLf, 1, argv);
});
args.GetReturnValue().Set(args.Holder());
}
template <typename APP>
void uWS_App(const FunctionCallbackInfo<Value> &args) {
@ -496,6 +515,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
/* SNI */
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "addServerName", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_addServerName<APP>, args.Data()));
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "removeServerName", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_removeServerName<APP>, args.Data()));
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "missingServerName", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_missingServerName<APP>, args.Data()));
Local<Object> localApp = appTemplate->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
localApp->SetAlignedPointerInInternalField(0, app);

@ -1 +1 @@
Subproject commit 77aced05f8ed262287583299bd86641f40d87cb5
Subproject commit f69282c478abe97095b7a34739c176a0c0c2cf60