DeOSphere
  • All Resources & Services
    • Compute
      • Virtual Instances
      • Bare Metal Instances
      • Managed Kubernetes
      • Big Data
      • Functions Engine
      • Data Protection
    • Services
      • Managed Databases
      • Applications Marketplace
      • Orchestration
      • Developer Tools
      • Management Tools
      • User Interface
    • Storage
      • Object Storage
      • Block Storage
      • File Storage
    • Networking
      • Software-Defined Networking
  • Why Choose DeOSphere?
  • Pricing
  • Security
  • About
DeOSphere
  • All Resources & Services
    • Compute
      • Virtual Instances
      • Bare Metal Instances
      • Managed Kubernetes
      • Big Data
      • Functions Engine
      • Data Protection
    • Services
      • Managed Databases
      • Applications Marketplace
      • Orchestration
      • Developer Tools
      • Management Tools
      • User Interface
    • Storage
      • Object Storage
      • Block Storage
      • File Storage
    • Networking
      • Software-Defined Networking
  • Why Choose DeOSphere?
  • Pricing
  • Security
  • About

Making a React application with reverse proxy and environment-awareness

byYulong Song inDevelopers Corner posted onAugust 1, 2019
0
0
Making a React application with reverse proxy and environment-awareness

A little introduction to what I would like to achieve. I have been working on the frontend for quite some time. I upgrade all my React dependencies to the latest stable versions (it’s all about hooks!) and use Webpack to optimize my build to the maximum (tree-shaking, compression, chunk splitting, etc.). Now I have two problems:

  1. How do I serve my minimized and compressed JavaScript and CSS bundles as a microservice?
  2. How do I switch my gateway endpoint from the development environment to the staging/production environment? For example, in the development environment, all the API calls should go to https://dev.gateway.io and in the production environment, they should go to https://gateway.io without my having to rebuild the whole project.

In the next sections, I will explain how I tackled these two problems.

How to serve minimized and compressed JS and CSS bundles as a microservice?

I’m using compression-webpack-plugin as a result, I have my bundles like app.bundle.83b334b1c8ef06b0b956.js.gz and app.83b334b1c8ef06b0b956.css.gz.

I need a static server to host these bundles and also be able to serve compressed files. What will be the best candidate? It doesn’t require much research to come to the conclusion: Nginx.

Here is my Dockerfile:

# Node image
FROM node:10 as builder

# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app

# copy source code
COPY . /usr/src/app/

# install app dependencies
RUN npm install

# run production build
RUN npm run production

# Nginx
FROM nginx:1.15
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx
COPY — from=builder /usr/src/app/app-build /usr/share/nginx/html
EXPOSE 80 
CMD [“nginx”, “-g”, “daemon off;”]

Here is my Nginx conf.d. I enabled the gzip with gzip_static on:

server {
  listen 80;
  location / {
    gzip_static on;
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;
  }
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }
}

Now you can run the image on your local to verify the result. Your website should be waiting for you at http://localhost.

How to switch gateway endpoints from the development environment to the staging/production environment?

Actually, this process can be generalized for injecting any environment variable on the frontend. The way I did it is through the index.html with a small env.js.

My env.js looks like this:

window.DEV_ENDPOINT = 'https://dev.gateway.io';

My index.html looks like this:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
    </head>
    <body>
        <div id="root">Loading...</div>        <!-- inject the env -->
        <script type="text/javascript" src="/config/env.js"></script>
    </body>
</html>

This is where I use the DEV_ENDPOINT:

const instance = axios.create({
        baseURL: window.DEV_ENDPOINT || CommonConstants.BASE_URL
    });

BASE_URL is actually the production gateway endpoint. As a result, if DEV_ENDPOINT is not presented, it will fall back to the production endpoint. You can define anything in this env.js. Now that we’ve finished the development setup, we need to wrap everything into Kubernetes.

Kubernetes provides configmap to achieve something to this effect. Here is the configmap YAML:

apiVersion: v1
kind: ConfigMap
metadata:
  name: frontend-dev-configmap
  labels:
    name: frontend-dev-configmap
data:
  endpoint-config: |
    window.DEV_ENDPOINT = 'https://dev.gateway.io';

And here is the deployment YAML:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: frontend
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - name: frontend-container
        image: frontend:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          name: http
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 3
          successThreshold: 1
        volumeMounts:
        - name: env-config
          mountPath: /usr/share/nginx/html/config
      volumes:
        - name: env-config
          configMap:
            name: frontend-dev-configmap
            items:
              - key: endpoint-config
                path: env.js

Now Kubernetes will create the env.js at /usr/share/nginx/html/config before starting the frontend container.

That’s it!

This article was originally published on Medium.

OpenStack Summit

Share:
Yulong Song

Yulong leads the team that’s developing Ormuco's dynamic application deployment platform, with responsibilities in front-end development and DevOps. Yulong has previously worked as a Full-Stack Developer at Ormuco. He graduated with a Master of Computer Science from Concordia University and a Bachelor of Management Science from University of Shanghai for Science and Technology.

Previous

Currying Functions in JavaScript, Recursively

Next

[PR] Quebec Ministry of Economy and Innovation Allocates $4 Million to Montreal-Based Edge Computing Firm, Ormuco

Keep on reading

Search

Categories

  • ! Без рубрики
  • 1
  • 100%A Z
  • 11
  • 111
  • 12
  • 1200 Z
  • 1200 Z
  • 13
  • 1500 Z
  • 1500 Z
  • 1500 Z
  • 1500A Z
  • 19
  • 2
  • 2000 Z
  • 2000A Z
  • 20bet
  • 25
  • 3
  • 4
  • 5
  • 500A Z
  • 6
  • 7
  • a16z generative ai
  • Ace Spinz Casino
  • All Check
  • ar-t1-aio
  • asterisk-support.rubadges 100
  • asterisk-support.ruquestion87844jetton-vhod 800
  • aug_bahsegel
  • aug_ch_common
  • aug_pinco
  • avite.ru a 1500
  • azurslot
  • Baxterbet Casino
  • best online casino
  • bestcasinogame151017-18
  • bestslotcasino21101
  • Betero Casino
  • Betfouru Casino
  • Betify
  • bh
  • bh_1
  • bh_main_may
  • bizzo casino
  • bk-pokerdom-bonus.clients.site 501
  • Blog
  • BLOG DE
  • blog-ch
  • bonus-kod-pokerdom-promokod.clients.site 510
  • Bonuskong Casino
  • bonusy-v-pokerdom.clients.site 520
  • boomerang
  • Bruno Casino Login
  • bt
  • bt_main
  • Business
  • campobet
  • casino
  • Casino AT
  • casino bez vkladu
  • casino ch
  • Casino DE
  • Casino Lizaro
  • Casino Snatch
  • Casino uden ROFUS
  • casino utan svensk licens
  • casino zonder crucks
  • Casino-GR
  • casino/betting/nutra
  • Casino1
  • Casino2
  • Casino3
  • Casino4
  • casino7k-cash.cam 700 b
  • Casperbets Casino
  • ch
  • ChanceBit Casino
  • Channel News
  • Chanze Casino
  • Chicken Road 2
  • Cloud News
  • cocobet
  • coldgrindorganic.com
  • comp-doma.ru a 1200
  • Computers, Games
  • Construction News
  • crossarea.ru a 1200
  • crownplay
  • crypto
  • CuppaWins Casino
  • Daily Mriya Social
  • de.trustpilot.com 1500
  • deutschklasse.ru a 1500
  • Developers Corner
  • dyuc-kontakt.ru a 1500
  • ehorussia.ru a 1200
  • Escort Jobs
  • Euteller Kasinot
  • Evolve Casino
  • exactlyawards.ru a 1500
  • Fair Go Casino
  • fairspin
  • Fatbet Casino
  • findfood.ru 2000
  • fr t2
  • friroll-na-pokerdom.clients.site 513
  • gamblezen
  • Gamblezen Casino
  • Gambling
  • gambling, games
  • Golden Ring Casino
  • HR News
  • Ilmaiskierrokset Ilman Talletusta
  • ipg-ltd
  • ivspeedcentr.ru a 1200
  • Jackbit Casino
  • Jeu Du Poulet
  • jule_canli_common
  • jule_ch_main
  • Jule_pb_common
  • jule_pb_ormanistanbul.com
  • jule_pb_zurichberg.com
  • jule_sb_main
  • jully_rb_sarosdanenerede.com
  • july_pinco_common
  • July_pinco_Sepi
  • july_rb_common
  • july_rb_shopharbourroad.com
  • kak-poluchit-10-na-pokerdom.clients.site 542
  • kak-popolnit-schet-v-pokerdom.clients.site 506
  • Kakadu Casino
  • kakoj-promokod-v-pokerdom.clients.site 506
  • kazino-pokerdom-ofitsialnyj-1789481061433.clients.site 508
  • Kingdom Casino Login
  • Kingz Casino
  • kz-ru
  • lagazzettacatanese.it 453
  • Lamabet Casino
  • legiano
  • lippsy.se
  • liustudentsecondhand.se
  • Lizaro
  • Lizaro Casino
  • Lolajack Casino
  • Looniegold Casino
  • Lucki Casino
  • Lucky Minning Casino
  • luxury casino
  • Mafia Casino
  • Magic Win Casino
  • magius
  • Millioner Casino
  • Millionz Casino
  • Mino Casino
  • mystake
  • Mystake Casino
  • Nana Casino
  • nauticboats.ru 72
  • News
  • Ninewin
  • novos-casinos-2026
  • Nv Casino Online
  • oktober-adm.ru 250 a
  • online casino zahranicni
  • onlinecasinogame211023-24
  • onlyspins
  • ozwin
  • pages
  • Parhaat Kasinobonukset
  • paroli-friroll-pokerdom-1789558662627.clients.site 513
  • Paysafecard Casino
  • pb
  • pc
  • pistolo
  • platinum play
  • playamo
  • Playzini Casino
  • poker-pokerdom.clients.site 505
  • pokerdom
  • pokerdom test 2
  • pokerdom test 2 – Copy
  • pokerdom-avtomaty.clients.site 501
  • pokerdom-bk.clients.site 520
  • pokerdom-bonus-bez-depozita.clients.site 503
  • pokerdom-bonus-promokod-pri.clients.site 511
  • pokerdom-brauzer.clients.site 526
  • pokerdom-forum.clients.site 509
  • pokerdom-friroll-parol-na.clients.site 505
  • pokerdom-gorjachaja-linija.clients.site 509
  • pokerdom-klient-na-android.clients.site 1003
  • pokerdom-na-realnye-dengi-na.clients.site 518
  • pokerdom-na-realnye.clients.site 1001
  • pokerdom-ofitsialnyj-sajt-1789712039484.clients.site 509
  • pokerdom-ofitsialnyj-sajt-1789713208145.clients.site 512
  • pokerdom-ofitsialnyj-sajt-1790057697145.clients.site 508
  • pokerdom-ofitsialnyj-sajt-i.clients.site b 1000
  • pokerdom-ofitsialnyj-sajt-na-1789656400084.clients.site 507
  • pokerdom-ofitsialnyj-skachat-1790070149183.clients.site 534
  • pokerdom-otzyvy-2026.clients.site 1002
  • pokerdom-paroli-friroll.clients.site 503
  • pokerdom-poker-skachat-na-pk.clients.site 503
  • pokerdom-skachat-pk.clients.site 516
  • pokerdom-vhod-na-sajt.clients.site 518
  • pokerdom-vyvody.clients.site 511
  • pokerdom-zablokirovali.clients.site 516
  • Post
  • press
  • Press Releases
  • pro-sarapul.ru 250 b
  • proverka
  • pu
  • public
  • Qbet Casino
  • Qzino Casino
  • rabochij-promokod-pokerdom-1789539101435.clients.site 515
  • rb_kasynolupa
  • rb_main
  • rc-langepas.ru 2000
  • reklama-pokerdom.clients.site 517
  • Retail News
  • review
  • Ringospin Casino
  • robocat
  • Rokubet
  • roobet
  • rprf.ru b 200
  • sadisibiri.ru a 1200
  • Sankra
  • sat-ch
  • sb_main
  • ska-khabarovsk.ru
  • skachat-pokerdom-dlja-androida.clients.site 537
  • skopinmuseum.ru b 1300
  • slota
  • Slotexo Casino
  • slotsgem
  • Slottyway
  • spinanga
  • Spinboss Bonus
  • Spinboss Login
  • Spinfin Casino
  • SpinRain Casino
  • Spins
  • Spins Castle Casino
  • spinyoo
  • sportaza
  • stage4u.ru 2000
  • Stake Casino France
  • studio-petukh.ru a 1300
  • Superlines Casino
  • t.mePokerdom_2026
  • tarif73.ru a 1300
  • Technology
  • textsHU
  • thebeautifullife
  • Uncategorized
  • Uudet Kasinot Ilman Rekisteröitymistä
  • Uudet Verovapaat Nettikasinot
  • Uusi Kasino
  • Vasy Casino
  • Vegas Hero
  • Vegashero Casino
  • velobet
  • Velobet Casino
  • Verovapaa Casino
  • Verywell Casino
  • Vidobet Casino
  • VipLuck Casino
  • wazamba
  • Westace Casino
  • winbay
  • Winbig21 Casino
  • wingaga
  • Winit Casino
  • Winlegends Casino
  • Winnita Casino
  • winshark
  • wiz slots
  • www.admsoln.ru a 1500
  • www.cashbaka.ru 2000
  • www.investigatore-privato-agenzia-investigativa-viterbo.it 451
  • www.notarius-falkova.ru a 1200
  • www.vitaconsacrataliguria.it 452
  • xn—-itbjbj2arv.xn--p1ai a 1500
  • Zimpler Kasino
  • zoome casino
  • Блог
  • Казино
  • Сплиты
  • яокб.рф a 1200

DeOSphere

DeOSphere is an infrastructure-as-a-service platform that aggregates the computing resources of local data center providers, and transforms these resources into a global network of decentralized computing. Resources available on DeOSphere include compute, storage, networking, and databases.

Company

  • Why Choose DeOSphere?
  • Newsroom

Legal

  • Privacy Policy
  • Security
  • Pricing

Contact Us

  • info@deosphere.net