Coder Social home page Coder Social logo

nginx's Introduction

此镜像是为了解决 SPA 前端项目在 Docker 下的多环境部署问题,它可以在站点启动时把环境依赖参数自动注入到项目中。

快速上手

example 目录下包含了一个完整的示例项目,对一个已有的 SPA 项目来说,你可以按照下面的步骤做改造。

1. 添加配置文件

src/config目录下添加各环境下的配置文件,并按app.{profile}.json规范命名,如app.production.json

{
    "API_BASE_URL": "https://{your-api-site-domain}"
}

2. 在项目中使用配置

由于启动器会把环境变量注入到 window.config 全局变量中,所以项目中使用环境变量的方式需要做一些调整。

const baseUrl = window.config?.API_BASE_URL || import.meta.env.VITE_API_BASE_URL;

如果你使用了 TypeScript,你可能还需要扩展Window对象的定义以通过编译,在 config 目录中新建一个 config.d.ts 文件,并输入如下内容

interface Window {
    config?: {
        API_BASE_URL: string
    }
}

现在你只需要在.env.development.env.local中添加开发环境的配置参数即可,其它环境下的配置你应该把它们挪到config目录中。

3. 添加 Dockerfile 文件

假设项目输出目录为 dist,把下面三行代码复制到 Dockerfile 文件中即可构建可支持多环境的通用镜像。

FROM cuigh/nginx
COPY dist .
COPY src/config config/

4. 启动站点

启动容器时通过profile环境变量激活指定环境的配置参数。

docker run -e PROFILE=prd --name test -it -p 8080:80 test

5. 高级功能

  1. 如果你喜欢,你可以使用 yaml 格式的配置文件。
  2. 如果你喜欢,你依然可以使用 .env.{profile} 文件来存放配置,从而继续享受美好的旧时光。

需要注意的是,无论使用哪种配置文件,在构建 Docker 镜像时一定要把配置文件包含进去。

nginx's People

Contributors

cuigh avatar

Stargazers

 avatar  avatar

nginx's Issues

同学,您这个项目引入了175个开源组件,存在3个漏洞,辛苦升级一下

检测到 cuigh/nginx 一共引入了175个开源组件,存在3个漏洞

漏洞标题:jwt-go 安全漏洞
缺陷组件:github.com/dgrijalva/[email protected]+incompatible
漏洞编号:CVE-2020-26160
漏洞描述:jwt-go是个人开发者的一个Go语言的JWT实现。
jwt-go 4.0.0-preview1之前版本存在安全漏洞。攻击者可利用该漏洞在使用[]string{} for m[\"aud\"](规范允许)的情况下绕过预期的访问限制。
影响范围:(∞, 4.0.0-preview1)
最小修复版本:4.0.0-preview1
缺陷组件引入路径:pike@->github.com/dgrijalva/[email protected]+incompatible

另外还有3个漏洞,详细报告:https://mofeisec.com/jr?p=af8ec9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.