From 3f0b94ab3eaf95b9d10772554f1cf5d74092ac5a Mon Sep 17 00:00:00 2001 From: Nico R Date: Thu, 22 Nov 2018 22:34:43 -0300 Subject: [PATCH 1/3] Heroku instructions based on express server --- docs/guide/deployment.md | 43 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/guide/deployment.md b/docs/guide/deployment.md index 243722fecb..9a248f2b2c 100644 --- a/docs/guide/deployment.md +++ b/docs/guide/deployment.md @@ -252,7 +252,48 @@ npm install -g now ### Heroku -> TODO | Open to contribution. +1. Create a `server.js` file in the root of your project +1. Add post install and start scripts to your `package.json` file +1. You might need to add `es6-promise` as a dev dependency (`npm install --save-dev es6-promise`) + +``` +// server.js +const express = require('express') +const path = require('path') +const serveStatic = require('serve-static') + +const app = express() +app.use(serveStatic(path.join(__dirname, '/dist'))) + +app.use((req, res, next) => { + res.status(404) + + if (req.accepts('html')) { + res.sendFile(path.join(__dirname, '/dist/index.html')) + return + } + + if (req.accepts('json')) { + res.send({ error: 'Not found' }) + return + } + + res.type('txt').send('Not found') +}) + +var port = process.env.PORT || 80 +app.listen(port) + +console.log('Your vue app is being hosted on port ' + port) +``` + +``` +// package.json +... + "postinstall": "npm run build", + "start": "node server.js" +... +``` ### Surge From 7c02a274b1a64bf3ad70aa2fd41b5857b7296335 Mon Sep 17 00:00:00 2001 From: Nico R Date: Thu, 22 Nov 2018 22:51:51 -0300 Subject: [PATCH 2/3] Using the correct formatting for javascript --- docs/guide/deployment.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/deployment.md b/docs/guide/deployment.md index 9a248f2b2c..b6c5019aeb 100644 --- a/docs/guide/deployment.md +++ b/docs/guide/deployment.md @@ -256,7 +256,7 @@ npm install -g now 1. Add post install and start scripts to your `package.json` file 1. You might need to add `es6-promise` as a dev dependency (`npm install --save-dev es6-promise`) -``` +```javascript // server.js const express = require('express') const path = require('path') @@ -287,11 +287,11 @@ app.listen(port) console.log('Your vue app is being hosted on port ' + port) ``` -``` +```json // package.json ... - "postinstall": "npm run build", - "start": "node server.js" +"postinstall": "npm run build", +"start": "node server.js" ... ``` From 2a31be8927f4c62d7881396dd5637433a94d37ce Mon Sep 17 00:00:00 2001 From: Nico R Date: Thu, 22 Nov 2018 23:13:41 -0300 Subject: [PATCH 3/3] Install dependency (expressjs) --- docs/guide/deployment.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/guide/deployment.md b/docs/guide/deployment.md index b6c5019aeb..4fc056fe25 100644 --- a/docs/guide/deployment.md +++ b/docs/guide/deployment.md @@ -254,6 +254,7 @@ npm install -g now 1. Create a `server.js` file in the root of your project 1. Add post install and start scripts to your `package.json` file +1. Install expressjs `npm install --save express` 1. You might need to add `es6-promise` as a dev dependency (`npm install --save-dev es6-promise`) ```javascript