GithubHelp home page GithubHelp logo

yukiyokotani / my-app Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.96 MB

Prototype of simple microservice architecture.

License: MIT License

Shell 4.28% Dockerfile 1.51% Go 23.39% JavaScript 1.65% TypeScript 68.94% Makefile 0.24%
nginx docker postgres golang react

my-app's Introduction

WEBアプリケーション雛形 (作成中)

ESLint Jest

構成

Application Server (Go), Web Server (NGINX), Reverse Proxy Server (NGINX), DB はそれぞれ Docker コンテナで用意している。同一ネットワークで実行するため docker-compose で起動させる。

メモ

単体の起動

  • GolangのAPIサーバーは golang ディレクトリから以下で起動
    go run main.go
  • Reactアプリケーションは react ディレクトリから以下で起動
    npm run dev

開発環境用コンテナの起動(開発時は基本的にこちらを推奨)

  • 事前準備(この手順を踏まないとコンテナが起動しない)

    • mkcert によって localhost 用の localhost.pemlocalhost-key.pem を作成する。 [参考]
    brew install mkcert // 未インストールの場合のみ
    mkcert --install
    mkcert localhost
    • 作成した pem ファイル localhost.pem, localhost-key.pem./nginx 下に置く。これで NGINX のリバースプロキシサーバー https://localhosthttps 接続できるようになる。(クライアントサーバー http://localhost:3000express で用意しており、こちらは https 接続できないので注意。またその影響で CORS 制限があり、API も利用できないようになっている。)
  • 開発環境を起動する際は root で以下を実行

    docker-compose build
    docker-compose up -d
    • 立ち上がったら https://localhost にアクセスする
      • 起動状況を確認するために Docker Desktop があると便利
    • サーバー・クライアントともに保存で再ビルドされ、コンテナを立ち上げなおさずともホットリロードで反映される
  • 開発環境を終了する際は以下を実行

    docker-compose down

デプロイ用コンテナの起動

  • .env.example を参考に .env ファイルを用意する。Postgres の情報と OpenID Connect の情報、どちらとも正しい情報に書き換える必要がある。OpenID Connect については Google アカウントによる認証を想定している。詳しくは auth_api.go を参照。
  • 現在の API の設計上、OpenID による認証を有効にするとき、Google の認証情報設定でリダイレクトURLのパスは api/auth/callback にする必要がある。
  • 以下を実行する。
    docker-compose -f docker-compose.prod.yml up -d
    デプロイ用コンテナでは Go のビルド、Next.js の静的ファイル出力が行われる。

my-app's People

Contributors

yukiyokotani avatar dependabot[bot] avatar

Stargazers

Roman avatar

Watchers

 avatar

my-app's Issues

nginxのreverse proxyの修正

  • localhost:3000 (express の clientサーバー) では express の設定 で /api8080 port に proxy する
  • localhost:443 (nginx の rever) では nginx の設定で /api8080 port に proxy する
  • localhost:8080 (golang の api サーバー) はレスポンスヘッダに Allow-Origin を設定する

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.