diff --git a/.travis.yml b/.travis.yml index 72300e33..5e42b923 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,9 @@ before_install: before_script: - export DATABASE_TEST_URL=postgres://postgres:@localhost:5432/mpwo_test - export APP_SETTINGS=mpwo_api.config.TestingConfig - - export REACT_APP_USERS_SERVICE_URL=http://0.0.0.0:5000/api/ + - export REACT_APP_API_URL=http://localhost:5000/api/ - export NODE_ENV=development - - export TEST_URL=http://0.0.0.0:3000 + - export TEST_URL=http://localhost:3000 - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - sleep 3 diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index 9890452f..d9bb149b 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -13,9 +13,7 @@ services: api: container_name: api - build: - context: https://github.com/SamR1/mpwo.git#master:mpwo_api - dockerfile: Dockerfile-ci + build: https://github.com/SamR1/mpwo.git#master:mpwo_api ports: - 5001:5000 environment: @@ -33,10 +31,10 @@ services: container_name: client build: context: https://github.com/SamR1/mpwo.git - dockerfile: ./mpwo_client/Dockerfile-ci + dockerfile: ./mpwo_client/Dockerfile args: - NODE_ENV=development - - REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL} + - REACT_APP_API_URL=${REACT_APP_API_URL} ports: - 3007:3000 depends_on: diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 23db37c9..bebe9475 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -2,42 +2,39 @@ version: '3.3' services: - db: - container_name: db - build: - context: ./mpwo_api/db - dockerfile: Dockerfile + api-db: + container_name: api-db + build: ./mpwo_api/db ports: - 5435:5432 environment: - - POSTGRES_USER=mpwo - - POSTGRES_PASSWORD=mpwo + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres api: container_name: api - build: - context: ./mpwo_api - dockerfile: Dockerfile-dev + build: ./mpwo_api ports: - 5001:5000 environment: + - DATABASE_URL=postgres://postgres:postgres@api-db:5432/mpwo + - DATABASE_TEST_URL=postgres://postgres:postgres@api-db:5432/mpwo_test - FLASK_APP=server.py - FLASK_DEBUG=1 - APP_SETTINGS=mpwo_api.config.DevelopmentConfig - - DATABASE_URL=postgres://mpwo:mpwo@db:5432/mpwo depends_on: - - db + - api-db links: - - db + - api-db client: container_name: client build: context: ./ - dockerfile: ./mpwo_client/Dockerfile-dev + dockerfile: ./mpwo_client/Dockerfile args: - NODE_ENV=development - - REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL} + - REACT_APP_API_URL=${REACT_APP_API_URL} ports: - 3007:3000 depends_on: diff --git a/mpwo_api/Dockerfile-ci b/mpwo_api/Dockerfile similarity index 100% rename from mpwo_api/Dockerfile-ci rename to mpwo_api/Dockerfile diff --git a/mpwo_api/Dockerfile-dev b/mpwo_api/Dockerfile-dev deleted file mode 100644 index 9e706603..00000000 --- a/mpwo_api/Dockerfile-dev +++ /dev/null @@ -1,17 +0,0 @@ -FROM python:3.6.3 - -# set working directory -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -# add requirements -ADD ./requirements.txt /usr/src/app/mpwo_api/requirements.txt - -# install requirements -RUN pip install -r mpwo_api/requirements.txt - -# add app -ADD . /usr/src/app - -# run server -CMD flask run --with-threads -h 0.0.0.0 diff --git a/mpwo_api/db/Dockerfile b/mpwo_api/db/Dockerfile index 447c640e..25cd4153 100644 --- a/mpwo_api/db/Dockerfile +++ b/mpwo_api/db/Dockerfile @@ -1,3 +1,3 @@ FROM postgres -ADD mpwo.sql /docker-entrypoint-initdb.d +ADD create.sql /docker-entrypoint-initdb.d diff --git a/mpwo_api/db/mpwo.sql b/mpwo_api/db/create.sql similarity index 100% rename from mpwo_api/db/mpwo.sql rename to mpwo_api/db/create.sql diff --git a/mpwo_client/Dockerfile-ci b/mpwo_client/Dockerfile similarity index 60% rename from mpwo_client/Dockerfile-ci rename to mpwo_client/Dockerfile index 8af5cf7d..9ce640d6 100644 --- a/mpwo_client/Dockerfile-ci +++ b/mpwo_client/Dockerfile @@ -5,21 +5,21 @@ RUN mkdir /usr/src/app WORKDIR /usr/src/app # add `/usr/src/app/node_modules/.bin` to $PATH -ENV PATH /app/node_modules/.bin:$PATH +ENV PATH /usr/src/app/node_modules/.bin:$PATH # add environment variables -ARG REACT_APP_USERS_SERVICE_URL +ARG REACT_APP_API_URL ARG NODE_ENV ENV NODE_ENV $NODE_ENV -ENV REACT_APP_USERS_SERVICE_URL $REACT_APP_USERS_SERVICE_URL +ENV REACT_APP_API_URL $REACT_APP_API_URL # install and cache app dependencies ADD package.json /usr/src/app/package.json -RUN npm install --silent -RUN npm install react-scripts -g +RUN yarn install --silent +RUN yarn global add react-scripts # add app ADD . /usr/src/app/ # start app -CMD ["npm", "start"] +CMD yarn start diff --git a/mpwo_client/Dockerfile-dev b/mpwo_client/Dockerfile-dev deleted file mode 100644 index 8af5cf7d..00000000 --- a/mpwo_client/Dockerfile-dev +++ /dev/null @@ -1,25 +0,0 @@ -FROM node:latest - -# set working directory -RUN mkdir /usr/src/app -WORKDIR /usr/src/app - -# add `/usr/src/app/node_modules/.bin` to $PATH -ENV PATH /app/node_modules/.bin:$PATH - -# add environment variables -ARG REACT_APP_USERS_SERVICE_URL -ARG NODE_ENV -ENV NODE_ENV $NODE_ENV -ENV REACT_APP_USERS_SERVICE_URL $REACT_APP_USERS_SERVICE_URL - -# install and cache app dependencies -ADD package.json /usr/src/app/package.json -RUN npm install --silent -RUN npm install react-scripts -g - -# add app -ADD . /usr/src/app/ - -# start app -CMD ["npm", "start"] diff --git a/mpwo_client/package.json b/mpwo_client/package.json index 7364c2e9..d139129d 100644 --- a/mpwo_client/package.json +++ b/mpwo_client/package.json @@ -1,35 +1,4 @@ { "name": "mpwo_client", - "version": "0.1.0", - "private": true, - "dependencies": { - "date-fns": "^1.29.0", - "history": "^4.7.2", - "react": "^16.2.0", - "react-dom": "^16.2.0", - "react-helmet": "^5.2.0", - "react-key-index": "^0.1.1", - "react-redux": "^5.0.6", - "react-router-dom": "^4.2.2", - "react-router-redux": "^5.0.0-alpha.9", - "react-scripts": "1.0.17", - "redux": "^3.7.2", - "redux-thunk": "^2.2.0" - }, - "scripts": { - "start": "cd mpwo_client && react-scripts start", - "build": "cd mpwo_client && react-scripts build", - "test": "cd mpwo_client && testcafe firefox e2e", - "eject": "cd mpwo_client && react-scripts eject", - "lint": "cd mpwo_client && eslint --cache --ext .jsx --ext .js src" - }, - "devDependencies": { - "babel-eslint": "^8.0.3", - "eslint": "^4.13.1", - "eslint-plugin-import": "^2.8.0", - "eslint-plugin-react": "^7.5.1", - "eslint-plugin-testcafe": "^0.2.1", - "randomstring": "^1.1.5", - "testcafe": "^0.18.6" - } + "version": "0.1.0" } diff --git a/mpwo_client/src/actions/index.js b/mpwo_client/src/actions/index.js index 274db981..8429a323 100644 --- a/mpwo_client/src/actions/index.js +++ b/mpwo_client/src/actions/index.js @@ -1,7 +1,7 @@ -import keyIndex from 'react-key-index' - import mpwoApi from '../mpwoApi' import { history } from '../index' +import { generateIds } from '../utils' + function AuthError(message) { return { type: 'AUTH_ERROR', message } @@ -138,7 +138,7 @@ export function handleUserFormSubmit(event, formType) { if (ret.length === 0) { dispatch(register(formData.formData)) } else { - dispatch(AuthErrors(keyIndex(ret, 1))) + dispatch(AuthErrors(generateIds(ret))) } } } diff --git a/mpwo_client/src/mpwoApi.js b/mpwo_client/src/mpwoApi.js index 31455618..c2438af7 100644 --- a/mpwo_client/src/mpwoApi.js +++ b/mpwo_client/src/mpwoApi.js @@ -1,6 +1,5 @@ const apiUrl = `${process.env.REACT_APP_API_URL}` - export default class MpwoApi { static login(email, password) { const request = new Request(`${apiUrl}auth/login`, { diff --git a/mpwo_client/src/utils.js b/mpwo_client/src/utils.js index 85f770ac..ff0e1371 100644 --- a/mpwo_client/src/utils.js +++ b/mpwo_client/src/utils.js @@ -1 +1,13 @@ + + export const isLoggedIn = () => !!window.localStorage.authToken + +export function generateIds(arr) { + let i = 0 + let arrWithIds = arr.map(arr => { + const obj = { id: i, value: arr } + i++ + return obj + }) + return arrWithIds +} diff --git a/package-lock.json b/package-lock.json index df12c58b..b5a18825 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2761,6 +2761,11 @@ "cssom": "0.3.2" } }, + "cuid": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/cuid/-/cuid-2.0.2.tgz", + "integrity": "sha512-dzz/KESlvSRPnAoThLqxHGfW94rtPYrHpQ8OpT5WwfJVlhysPw1U989+3fHrn/FdtuMrFW5dzOVR/CAb90RbNw==" + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", diff --git a/package.json b/package.json index 7364c2e9..8283f5ea 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,12 @@ "version": "0.1.0", "private": true, "dependencies": { + "chalk": "2.3.0", "date-fns": "^1.29.0", "history": "^4.7.2", "react": "^16.2.0", "react-dom": "^16.2.0", "react-helmet": "^5.2.0", - "react-key-index": "^0.1.1", "react-redux": "^5.0.6", "react-router-dom": "^4.2.2", "react-router-redux": "^5.0.0-alpha.9",