From fda241ae11093ca705cb0bd6be951989b07961e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 20 Oct 2018 01:40:37 +0200 Subject: [PATCH 1/2] Yarn run start should not set NODE_ENV=production Running the app without nodemon is a valid use case. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41e762964..2125914ff 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "postinstall": "yarn styleguide:build", "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server", "build": "nuxt build", - "start": "cross-env NODE_ENV=production node server/index.js", + "start": "cross-env node server/index.js", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "styleguide": "cd ./styleguide && yarn dev", From 41ece7dce115be5ef1d1b1ca916e8b96aa3c760f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 20 Oct 2018 01:41:19 +0200 Subject: [PATCH 2/2] Provide an Installation with Docker --- .dockerignore | 10 ++++++++++ Dockerfile | 23 +++++++++++++++++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ nuxt.config.js | 33 +++------------------------------ plugins/apollo-config.js | 13 +++++++++++++ 5 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 plugins/apollo-config.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..f363d4044 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.vscode/ + +styleguide/node_modules/ +node_modules/ +npm-debug.log + +Dockerfile +docker-compose*.yml + +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..d0d0e28dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:10-alpine +LABEL Description="This image builds and runs the Human-Connection Web Application Frontend" Vendor="Human-Connection gGmbH" Version="0.0.1" Maintainer="Human-Connection gGmbH (developer@human-connection.org)" + +# expose the app port +EXPOSE 3000 + +ARG WORKDIR=/HC-WebApp +RUN mkdir -p $WORKDIR +WORKDIR $WORKDIR + +# See: https://github.com/nodejs/docker-node/pull/367#issuecomment-430807898 +RUN apk --no-cache add git + +COPY styleguide/ ./styleguide +RUN cd styleguide && yarn install --production=false --frozen-lockfile --non-interactive --ignore-engines + +COPY package.json . +COPY yarn.lock . +RUN yarn install --production=false --frozen-lockfile --non-interactive --ignore-engines + +COPY . . +RUN ["yarn", "run", "build"] +CMD ["yarn", "run", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..f6ce6ff93 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + webapp: + build: + context: . + ports: + - 3000:3000 + - 8080:8080 + networks: + - hc-network + volumes: + - .:/HC-WebApp + - node_modules:/HC-WebApp/node_modules + command: yarn run dev + environment: + - HOST=0.0.0.0 + - BACKEND_URL=http://backend.127.0.0.1.xip.io:4000 + +networks: + hc-network: + name: hc-network + +volumes: + node_modules: diff --git a/nuxt.config.js b/nuxt.config.js index 99726e447..59588a8ee 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,18 +1,11 @@ const pkg = require('./package') const envWhitelist = [ - 'BUILD_COMMIT', 'NODE_ENV', - 'WEBAPP_HOST', - 'WEBAPP_PORT', - 'WEBAPP_BASE_URL', - 'API_HOST', - 'API_PORT', - 'EMBED_API_URL', - 'SENTRY_DNS_PUBLIC', - 'MAPBOX_TOKEN', + 'BACKEND_URL', 'MAINTENANCE' ] + module.exports = { mode: 'universal', @@ -136,27 +129,7 @@ module.exports = { // }, // required clientConfigs: { - default: { - // required - httpEndpoint: 'http://localhost:4000', - // optional - // See https://www.apollographql.com/docs/link/links/http.html#options - httpLinkOptions: { - credentials: 'same-origin' - }, - credentials: true, - - // You can use `wss` for secure connection (recommended in production) - // Use `null` to disable subscriptions - // wsEndpoint: 'ws://localhost:4000', // optional - // LocalStorage token - tokenName: 'apollo-token', // optional - // Enable Automatic Query persisting with Apollo Engine - persisting: false, // Optional - // Use websockets for everything (no HTTP) - // You need to pass a `wsEndpoint` for this to work - websocketsOnly: false // Optional - } + default: '~/plugins/apollo-config.js', } }, diff --git a/plugins/apollo-config.js b/plugins/apollo-config.js new file mode 100644 index 000000000..866d3ee92 --- /dev/null +++ b/plugins/apollo-config.js @@ -0,0 +1,13 @@ +export default function({ app }) { + const backendUrl = app.$env.BACKEND_URL || 'http://localhost:4000' + return { + httpEndpoint: backendUrl, + httpLinkOptions: { + credentials: 'same-origin' + }, + credentials: true, + tokenName: 'apollo-token', + persisting: false, + websocketsOnly: false + } +}