vue.js - 如何将我的私有 api 密钥存储在 Vue.js 应用程序上?
问题描述
我阅读了有关 Vue CLI 的文档,我想确定我是否理解正确。
文件说,
Note that only NODE_ENV, BASE_URL, and variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. It is to avoid accidentally exposing a private key on the machine that could have the same name.
那么这是否意味着我应该在没有前缀 VUE_APP 的情况下存储我的私钥?例如,
VUE_APP_NOT_SECRET_KEY=not_secret_key
SECRET_KEY=secret_key
存储我的密钥的正确方法是什么?
解决方案
您可以将密钥存储在 VUE_APP_NOT_SECRET_KEY=not_secret_key
或 SECRET_KEY=secret_key
中,从安全的角度来看没有区别,任何具有最低前端技能的人都可以从浏览器中读取此值。
唯一的区别是,如果您使用VUE_APP_*
前缀,您的变量将位于 process.env 中,并且将在编译时使用 DefinePluing 被 Vue 替换。
cli.vuejs.org/guide/mode-and-env.html#environment-variables –</p>
注意:您存储在 Vue 应用程序中的任何内容都不是秘密。
推荐阅读
- python - 如何将 GEKKO 中的值转换为浮点数
- scala - 如何比较两个火花流作业的性能?
- c# - 如何将现有数据库记录放入 GirdView 以在 ASP.NET MVC 中执行 CRUD 操作?
- mysql - 如何在节点 js 中重新启动 mqtt 订阅者
- java - 在标记中显示信息
- hadoop - 如何将 Hadoop 版本从 3.2.1 转换为 2.2.0?
- google-analytics - 为什么onclick() gtag事件在其他事件都ok时没有出现在GA中
- r - r中的多维缩放与语料库
- angular - 对“环境”“环境”中的非导出函数的引用包含环境/环境.ts(29,10) 处的错误
- class - 是否有任何策略来划分应用 SRP 的责任?