首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >tinylicious服务器可以在3000以外的端口启动吗?

tinylicious服务器可以在3000以外的端口启动吗?
EN

Stack Overflow用户
提问于 2021-03-09 03:46:38
回答 2查看 133关注 0票数 0

tinylicious服务器可以在3000以外的端口启动吗?我尝试过像"PORT=4100 tinylicious“这样的东西,我可以看到终端日志说:

代码语言:javascript
运行
复制
@federation/shell-app: [1] info: Listening on port 4100 {"label":"winston","timestamp":"2021-03-08T19:23:37.861Z"}

但后来它在我的代码中失败了,表明服务调用出现了问题:

代码语言:javascript
运行
复制
main.js:15815 ERROR TypeError: Cannot read property 'shapeClicked' of undefined
    at Layer.onClick [as zzClickFunc] (collabmap.component.js:45)
    at JS:24817
    at Array.<anonymous> (JS:8190)
    at window.<computed> (JS:1111)
    at Object.<anonymous> (JS:51778)
    at j (JS:51777)

事实上,Network选项卡显示它仍在通过3000发布:

代码语言:javascript
运行
复制
Request URL: http://localhost:3000/documents/tinylicious
Referrer Policy: strict-origin-when-cross-origin

我知道tinylicious不是完整的Fluid服务器,它只是为了测试目的,所以它可能已经硬连到3000,但也许有人知道如何在不同的端口上启动它。

EN

回答 2

Stack Overflow用户

发布于 2021-03-13 08:52:44

Tinylicious服务器端口绝对是可配置的。

如果你覆盖了他们的库,那么你将能够使用任何可能的端口运行你的应用程序。

你一定注意到了这个函数:

代码语言:javascript
运行
复制
getTinyliciousContainer();

在它的库get-tinylicious container和tinylicious driver中,你会在tinylicious driver: insecureTinyliciousUrlResolver.ts中看到它们的一个文件,其中每个该死的host:port都被硬编码为localhost:3000。

因此,只需从他们的getTinyliciousContainer和tinylicious驱动程序中复制他们的代码,并制作您自己版本的getTinyliciousContainer。将来,您需要复制这些代码来配置Routerlicious,因为Tinylicious是非常轻量级的,建议仅用于测试目的。您需要在@fluidframework/tinylicious driver中修改的文件是insecureTinyliciousUrlResolver.ts:

代码语言:javascript
运行
复制
export class InsecureTinyliciousUrlResolver implements IUrlResolver {
public async resolve(request: IRequest): Promise<IResolvedUrl> {
    const url = request.url.replace(`http://${serviceHostName}:${servicePort}/`,"");
    const documentId = url.split("/")[0];
    const encodedDocId = encodeURIComponent(documentId);
    const documentRelativePath = url.slice(documentId.length);
    const serviceHostName = "YOUR-PREFERRED-HOST-NAME";
    const servicePort = "YOUR-PREFERRED-PORT";

    const documentUrl = `fluid://${serviceHostName}:${servicePort}/tinylicious/${encodedDocId}${documentRelativePath}`;
    const deltaStorageUrl = `http://${serviceHostName}:${servicePort}/deltas/tinylicious/${encodedDocId}`;
    const storageUrl = `http://${serviceHostName}:${servicePort}/repos/tinylicious`;

    const response: IFluidResolvedUrl = {
        endpoints: {
            deltaStorageUrl,
            ordererUrl: `http://${serviceHostName}:${servicePort}`,
            storageUrl,
        },
        tokens: { jwt: this.auth(documentId) },
        type: "fluid",
        url: documentUrl,
    };
    return response;
}

public async getAbsoluteUrl(resolvedUrl: IFluidResolvedUrl, relativeUrl: string): Promise<string> {
    const documentId = decodeURIComponent(resolvedUrl.url.replace(`fluid://${serviceHostName}:${servicePort}/tinylicious/`, ""));
    /*
     * The detached container flow will ultimately call getAbsoluteUrl() with the resolved.url produced by
     * resolve().  The container expects getAbsoluteUrl's return value to be a URL that can then be roundtripped
     * back through resolve() again, and get the same result again.  So we'll return a "URL" with the same format
     * described above.
     */
    return `${documentId}/${relativeUrl}`;
}

private auth(documentId: string) {
    const claims: ITokenClaims = {
        documentId,
        scopes: ["doc:read", "doc:write", "summary:write"],
        tenantId: "tinylicious",
        user: { id: uuid() },
        // @ts-ignore
        iat: Math.round(new Date().getTime() / 1000),
        exp: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour expiration
        ver: "1.0",
    };

    const utf8Key = { utf8: "12345" };
    return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg:"HS256", typ: "JWT" }), claims, utf8Key);
}
}

export const createTinyliciousCreateNewRequest =
    (documentId: string): IRequest=> (
        {
            url: documentId,
            headers:{
                createNew: true,
            },
        }
    );

然后,您只需独立运行此React应用程序,而不是并发运行,并且没有内置的Tinylicious服务器。

转到他们的GitHub,在FluidFramework/服务器资源库中克隆他们的Tinylicious,然后在你想要的任何端口上运行它。

现在,您可以在任何主机上、任何您想要的端口上运行Tinylicious。

票数 2
EN

Stack Overflow用户

发布于 2021-07-10 02:00:23

Tinylicious端口现在是可配置的。有关更多细节,请参阅https://github.com/microsoft/FluidFramework/issues/5415

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66536190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档