From a0e05a69e9a7e0b93e75dbba54bc6b4e5cf18b1c Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 21 Aug 2018 20:13:49 +0300 Subject: [PATCH] Improve docker configs and use web.sik.party:8000 as default backend --- .dockerignore | 3 ++- .env.sample | 2 +- configs/webpack/common.js | 16 ++++++++-------- configs/webpack/dev.js | 23 ++++------------------- configs/webpack/prod.js | 1 - docker-compose.prod.yml | 2 ++ docker-compose.yml | 9 +++++++++ package.json | 2 +- src/index.tsx | 2 ++ 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.dockerignore b/.dockerignore index 04c01ba..f94630c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ node_modules/ -dist/ \ No newline at end of file +dist/ +.env \ No newline at end of file diff --git a/.env.sample b/.env.sample index a901c8c..d3cf4b3 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1 @@ -API_URL=http://localhost:1234 \ No newline at end of file +API_URL=http://web.sik.party:8000/api \ No newline at end of file diff --git a/configs/webpack/common.js b/configs/webpack/common.js index bf8fe48..0384080 100644 --- a/configs/webpack/common.js +++ b/configs/webpack/common.js @@ -2,11 +2,11 @@ const {resolve} = require("path"); const {CheckerPlugin} = require("awesome-typescript-loader"); const StyleLintPlugin = require("stylelint-webpack-plugin"); -const Dotenv = require("dotenv-webpack"); +const webpack = require('webpack'); module.exports = function (env, argv) { const config = {}; - + config.resolve = { extensions: [".ts", ".tsx", ".js", ".jsx"] }; @@ -32,15 +32,15 @@ module.exports = function (env, argv) { ] }); + const envVars = {}; + Object.keys(process.env).forEach((key) => { + envVars[`process.env.${key}`] = JSON.stringify(process.env[key]); + }); + config.plugins = [ + new webpack.DefinePlugin(envVars), new CheckerPlugin(), new StyleLintPlugin(), - new Dotenv({ - path: "./.env.sample" - }), - new Dotenv({ - path: "./.env" - }), ]; config.performance = { diff --git a/configs/webpack/dev.js b/configs/webpack/dev.js index c49b1a0..d857336 100644 --- a/configs/webpack/dev.js +++ b/configs/webpack/dev.js @@ -3,6 +3,7 @@ const merge = require("webpack-merge"); const webpack = require("webpack"); const FaviconsWebpackPlugin = require("favicons-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); +const Dotenv = require("dotenv-webpack"); const commonConfig = require("./common.js"); @@ -24,28 +25,12 @@ module.exports = function (env, argv) { '.sik.party', '.sahkoinsinoorikilta.fi', ], - proxy: { - '/api': { - target: 'http://localhost:8000', - secure: false, - }, - }, - // clientLogLevel: 'none', - // https: settings.dev_server.https, - // host: settings.dev_server.host, - // port: settings.dev_server.port, - // contentBase: output.path, - // public: settings.dev_server.public, - // publicPath: output.publicPath, - // compress: true, - // headers: { 'Access-Control-Allow-Origin': '*' }, - // historyApiFallback: true, - // watchOptions: { - // ignored: /node_modules/ - // } }; base.devtool = "cheap-module-eval-source-map"; base.plugins = base.plugins.concat([ + new Dotenv({ + path: "./.env" + }), new FaviconsWebpackPlugin({ logo: "./assets/img/favicon.png", prefix: "assets/icons/", diff --git a/configs/webpack/prod.js b/configs/webpack/prod.js index 58187d0..8e23bab 100644 --- a/configs/webpack/prod.js +++ b/configs/webpack/prod.js @@ -8,7 +8,6 @@ const nodeExternals = require('webpack-node-externals'); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const WebpackCdnPlugin = require('webpack-cdn-plugin'); -const webpack = require('webpack'); /* NOTE: This is a list of all routes that are prerendered for production use. Please list all routes that contain search engine accessible content, i.e., diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 7dd260f..a28b26d 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -6,4 +6,6 @@ services: image: git.sahkoinsinoorikilta.fi:4567/vtmk/web2.0-frontend-prod ports: - "3000:3000" + environment: + API_URL: ${API_URL} command: npm run start-prod diff --git a/docker-compose.yml b/docker-compose.yml index f763b98..2afc821 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,3 +6,12 @@ services: image: git.sahkoinsinoorikilta.fi:4567/vtmk/web2.0-frontend ports: - "3000:3000" + environment: + API_URL: ${API_URL} + + mock-backend: + build: . + image: git.sahkoinsinoorikilta.fi:4567/vtmk/web2.0-frontend-mock-backend + ports: + - "1234:1234" + command: npm run mock-backend diff --git a/package.json b/package.json index fd4b236..5edbb06 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "start-dev": "webpack-dev-server --config=configs/webpack/dev.js", "serve": "node dist/js/server.js", "start-prod": "npm run build && npm run serve", - "mock-backend": "json-server --watch db.json -p 1234", + "mock-backend": "json-server --watch db.json -H 0.0.0.0 -p 1234", "test": "npm-run-all lint test:e2e", "test:e2e": "npm-run-all -s build test:e2e:run", "test:e2e:run": "npm-run-all -p -r mock-backend serve test:e2e:testcafe", diff --git a/src/index.tsx b/src/index.tsx index b57b146..2c5e515 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,8 @@ import {AppContainer} from "react-hot-loader"; import Routes from "./routes"; import "./index.scss"; +console.log("Using API URL: ", process.env.API_URL); + const rootEl = document.getElementById("root"); render(