public async serve()

in lib/host.ts [310:343]


    public async serve(request: string | Request): Promise<Response> {
        return new Promise<Host>(resolve => {
            if (typeof request === 'string') {
                request = utils.appendMessageOnException(
                    ". Fail to parse request string.",
                    () => { return JSON.parse(<string>request);});
            }

            // TODO: @daiyip, avoid extra parsing/serialization for host proxy.
            let appName = (<Request>request).application;
            if (appName == null) {
                let baseUri = (<Request>request).base;
                if (baseUri == null) {
                    throw new Error("Either 'application' or 'base' should be present in request.");
                }
                let lcUri = baseUri.toLowerCase();
                if (this._templateToAppNameMap.has(lcUri)) {
                    appName = this._templateToAppNameMap.get(lcUri);
                } else {
                    appName = this._templateLoader.getApplicationName(baseUri);
                    this._templateToAppNameMap.set(lcUri, appName);
                }
            }

            let lowerCaseName = appName.toLowerCase();
            if (!this._hostMap.has(lowerCaseName)) {
                throw new Error("Application '" + appName + "' is not registered for serving");
            }
            
            resolve(this._hostMap.get(lowerCaseName));
        }).then((host: Host) => {
            return host.serve(request);
        });
    }