【问题标题】:importing class will exposed other content of the file in meteor导入类将暴露流星中文件的其他内容
【发布时间】:2019-06-27 06:31:51
【问题描述】:

我在“/imports/api”目录中创建了一个文件。

这是一个简单的文件内容,

export default class Account {
    static get FUNCTIONS() {
        return ...
    }
    constructor() {
        this.prop1 = null;
    }
    ...
}


if (Meteor.isServer) {
    import ServerClass from './server';
    Meteor.methods(...)
}

这个文件被导入到 '/server' 目录。然后我使用

在客户端导入 Account 类
import Account from 'imports/api/Account'

它是否公开 Meteor.isServer 中的服务器端代码(Meteor 方法和发布)?

【问题讨论】:

    标签: reactjs meteor


    【解决方案1】:

    您从客户端导入的每个代码都将包含在客户端包中(但不一定是可执行的)。在您的情况下,用户将能够在网页的源文件中看到Meteor.isServer 的代码块,但他将无法访问这部分的功能。

    如果您在Meteor.isServer 中编写import 语句inside,那么此导入中的代码也将对客户端不可见

    【讨论】:

      猜你喜欢
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      相关资源
      最近更新 更多