Skip to content

Commit

Permalink
updated server.js reflecting vue-hackernews2 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gbezyuk committed Dec 19, 2016
1 parent 6226228 commit c1eac0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
dist/
npm-debug.log
.vscode/
yarn.lock
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"axios": "^0.13.1",
"compression": "^1.6.2",
"express": "^4.14.0",
"lru-cache": "^4.0.1",
"serialize-javascript": "^1.3.0",
Expand Down
13 changes: 11 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path')
const resolve = file => path.resolve(__dirname, file)
const express = require('express')
const favicon = require('serve-favicon')
const compression = require('compression')
const serialize = require('serialize-javascript')

const createBundleRenderer = require('vue-server-renderer').createBundleRenderer
Expand Down Expand Up @@ -44,8 +45,16 @@ function createRenderer (bundle) {
})
}

app.use('/dist', express.static(resolve('./dist')))
app.use(favicon(path.resolve(__dirname, 'src/assets/logo.png')))
const serve = (path, cache) => express.static(resolve(path), {
maxAge: cache && isProd ? 60 * 60 * 24 * 30 : 0
})

app.use(compression({ threshold: 0 }))
app.use(favicon('./src/assets/logo.png'))
app.use('/service-worker.js', serve('./dist/service-worker.js'))
app.use('/manifest.json', serve('./manifest.json'))
app.use('/dist', serve('./dist'))
app.use('/public', serve('./public'))

app.get('*', (req, res) => {
if (!renderer) {
Expand Down

0 comments on commit c1eac0d

Please sign in to comment.