定制 pnodev/pno-js-globals 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pnodev/pno-js-globals

最新稳定版本:1.1.0

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

统计信息

  • 总下载量: 378
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固