pnodev/pno-js-globals
Composer 安装命令:
composer require pnodev/pno-js-globals
包简介
Exposes public environment variables to JavaScript
README 文档
README
This is a simple extension that is able to expose environment variables to your JavaScript code.
A word on security
Accidentally exposing sensitive information is a big security risk. You certainly don't want secret information exposed to the client.
However, there are a lot of cases where you need to expose environment specific information
to your JavaScript (e.g. a Sentry token, API endpoints, etc.). To avoid exposing
variables that are not meant to be accessible to the public, this extension
will only expose environment variables that are prefixed with PUBLIC_. That way
you have a very specific indication that are variable is safe to be exposed.
How does it work?
Define your environment variables the way you are used to. We recommend using a .env file in combination with dotenv-connector by Helmut Hummel.
But you can choose any method you like. Just make sure that the env variables you
need are exposed to PHP. All variables you define prefixed with PUBLIC_ will then
be exposed to your JavaScript and made available under window._gloabls.
Example
# file: .env
API_KEY=a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1d # -> this will not be exposed
PUBLIC_SENTRY_DSN=https://XXXXXXXXXXXXX.ingest.us.sentry.io/XXXXXXX
// file: main.js
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: window._globals.PUBLIC_SENTRY_DSN,
// [...]
});
Installation
Install the extension via composer:
composer req pnodev/pno-js-globals
Import the TypoScript in your sitepackage:
// file: setup.typoscript
@import 'EXT:pno_js_globals/Configuration/TypoScript/setup.typoscript'
Roadmap / Planned features
- TypeScript support
pnodev/pno-js-globals 适用场景与选型建议
pnodev/pno-js-globals 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 380 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pnodev/pno-js-globals 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pnodev/pno-js-globals 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 380
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2024-06-21