From 1d81cfa163c5efba7ffe09305744c9bed957bf30 Mon Sep 17 00:00:00 2001 From: Harry Moreno Date: Wed, 20 Feb 2019 22:22:28 -0500 Subject: [PATCH] Herokuize project * add build step to project * add dev script * instruct to use DATABASE_URL * put morgan in dependencies * inspired by https://github.com/babel/example-node-server/blob/master/package.json --- .gitignore | 4 +-- README.md | 17 ++++++++---- package-lock.json | 70 +++++++++++++++++++++++++++++++++++++---------- package.json | 10 +++++-- 4 files changed, 75 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index ab79e99..73dfc40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ logfile .env - -node_modules/ \ No newline at end of file +dist/ +node_modules/ diff --git a/README.md b/README.md index a7564a2..4887d4b 100644 --- a/README.md +++ b/README.md @@ -42,19 +42,24 @@ Client Applications: * `npm install` * fill out *.env file* (see below) * start PostgreSQL database -* `npm start` +* `npm run dev` * visit `http://localhost:8000` for GraphQL playground +## Deployment + +Since we use modern javascript syntax, we need to perform a build step before +deploying to production. The compiled API is put in `lib/`. + +* provision postgres database +* `npm run build` +* `npm start` + #### .env file Since this boilerplate project is using PostgreSQL, you have to install it for your machine and get a database up and running. You find everything for the set up over here: [Setup PostgreSQL with Sequelize in Express Tutorial](https://www.robinwieruch.de/postgres-express-setup-tutorial). After you have created a database and a database user, you can fill out the environment variables in the *server/.env* file. ``` -DATABASE=mydatabase - -DATABASE_USER=postgres -DATABASE_PASSWORD=postgres - +DATABASE_URL=postgres://username:password@localhost:5432/mydatabase SECRET=asdlplplfwfwefwekwself.2342.dawasdq ``` diff --git a/package-lock.json b/package-lock.json index 224d3b0..10adb2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,24 @@ "resolved": "https://registry.npmjs.org/@apollographql/graphql-playground-html/-/graphql-playground-html-1.6.4.tgz", "integrity": "sha512-gwvaQO6/Hv4DEwhDLmmu2tzCU9oPjC5Xl9Kk8Yd0IxyKhYLlLalmkMMjsZLzU5H3fGaalLD96OYfxHL0ClVUDQ==" }, + "@babel/cli": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.2.3.tgz", + "integrity": "sha512-bfna97nmJV6nDJhXNPeEfxyMjWnt6+IjUAaDPiYRTBlm8L41n8nvw6UAqUCbvpFfU246gHPxW7sfWwqtF4FcYA==", + "dev": true, + "requires": { + "chokidar": "^2.0.3", + "commander": "^2.8.1", + "convert-source-map": "^1.1.0", + "fs-readdir-recursive": "^1.1.0", + "glob": "^7.0.0", + "lodash": "^4.17.10", + "mkdirp": "^0.5.1", + "output-file-sync": "^2.0.0", + "slash": "^2.0.0", + "source-map": "^0.5.0" + } + }, "@babel/code-frame": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", @@ -1371,7 +1389,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", - "dev": true, "requires": { "safe-buffer": "5.1.2" } @@ -2763,7 +2780,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2784,12 +2802,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2804,17 +2824,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2931,7 +2954,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2943,6 +2967,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2957,6 +2982,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2964,12 +2990,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2988,6 +3016,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3068,7 +3097,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3080,6 +3110,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3165,7 +3196,8 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -3201,6 +3233,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3220,6 +3253,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3263,12 +3297,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -4212,7 +4248,6 @@ "version": "1.9.1", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", - "dev": true, "requires": { "basic-auth": "~2.0.0", "debug": "2.6.9", @@ -4435,8 +4470,7 @@ "on-headers": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", - "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=", - "dev": true + "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=" }, "once": { "version": "1.4.0", @@ -5144,6 +5178,12 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, + "slash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true + }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", diff --git a/package.json b/package.json index f0fffeb..207f5a0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "node": "10.11.0" }, "scripts": { - "start": "nodemon --exec babel-node src/index.js", + "start": "npm run build && node lib/index.js", + "build": "babel src --out-dir dist", + "dev": "nodemon --exec babel-node src/index.js", + "heroku-postbuild": "npm run build", "test:run-server": "TEST_DATABASE=mytestdatabase npm start", "test:execute-test": "mocha --require @babel/register 'src/**/*.spec.js'", "test": "echo \"No test specified\" && exit 0" @@ -16,6 +19,7 @@ "author": "Robin Wieruch (https://www.robinwieruch.de)", "license": "ISC", "devDependencies": { + "@babel/cli": "^7.2.3", "@babel/core": "^7.1.6", "@babel/node": "^7.0.0", "@babel/preset-env": "^7.1.6", @@ -23,8 +27,7 @@ "axios": "^0.18.0", "chai": "^4.2.0", "mocha": "^5.2.0", - "nodemon": "^1.18.7", - "morgan": "^1.9.1" + "nodemon": "^1.18.7" }, "dependencies": { "apollo-server": "^2.2.3", @@ -38,6 +41,7 @@ "graphql-iso-date": "^3.6.1", "graphql-resolvers": "^0.2.2", "jsonwebtoken": "^8.4.0", + "morgan": "^1.9.1", "pg": "^7.6.1", "sequelize": "^4.41.2", "uuid": "^3.3.2"