Commit dc919e7c authored by pooya parsa's avatar pooya parsa

prepare for now2

parent d2428aba
node_modules
.nuxt
dist
import express from 'express'
import apicache from 'apicache'
const app = express()
// https://github.com/kwhitley/apicache
app.use(apicache.middleware('15 minutes'))
// apicache.options({ debug: true })
export default {
path: '/api/',
handler: app
}
...@@ -38,10 +38,6 @@ export default { ...@@ -38,10 +38,6 @@ export default {
type: Object, type: Object,
required: true required: true
} }
},
// http://ssr.vuejs.org/en/caching.html#component-level-caching
serverCacheKey: ({ item: { id, __lastUpdated, time } }) => {
return `${id}::${__lastUpdated}::${timeAgo(time)}`
} }
} }
</script> </script>
......
...@@ -29,8 +29,7 @@ export default { ...@@ -29,8 +29,7 @@ export default {
type: Boolean, type: Boolean,
required: true required: true
} }
}, }
serverCacheKey: props => props.show
} }
</script> </script>
......
{
"version": 2,
"alias": "hn.nuxtjs.org",
"builds": [
{
"src": "nuxt.config.js",
"use": "@nuxtjs/now-builder",
"config": {
"serverFiles": [
"common/cache.js"
]
}
}
],
"routes": [
{ "src": "/_nuxt/.+", "headers": { "cache-control": "s-maxage=31536000" } },
{ "src": "/(.*)", "dest": "/" }
]
}
...@@ -2,37 +2,41 @@ export default { ...@@ -2,37 +2,41 @@ export default {
head: { head: {
titleTemplate: 'Nuxt HN | %s', titleTemplate: 'Nuxt HN | %s',
meta: [ meta: [
{ { property: 'og:image', content: 'https://user-images.githubusercontent.com/904724/26879447-689b56a8-4b91-11e7-968f-5eea1d6c71b4.png' },
property: 'og:image',
content:
'https://user-images.githubusercontent.com/904724/26879447-689b56a8-4b91-11e7-968f-5eea1d6c71b4.png'
},
{ property: 'twitter:card', content: 'summary_large_image' }, { property: 'twitter:card', content: 'summary_large_image' },
{ property: 'twitter:site', content: '@nuxt_js' } { property: 'twitter:site', content: '@nuxt_js' }
], ],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }] link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'dns-prefetch', href: 'https://api.hnpwa.com' },
{ rel: 'preconnect', href: 'https://api.hnpwa.com' }
]
}, },
loading: { loading: {
color: '#59cc93' color: '#59cc93'
}, },
manifest: { manifest: {
name: 'Nuxt Hacker News', name: 'Nuxt Hacker News',
short_name: 'Nuxt HN', short_name: 'Nuxt HN',
description: 'HackerNews clone built with Nuxt.js', description: 'HackerNews clone built with Nuxt.js',
theme_color: '#188269' theme_color: '#188269'
}, },
modules: ['@nuxtjs/pwa', '@nuxtjs/component-cache', '@nuxtjs/axios'],
modules: process.env.NODE_ENV === 'production' ? [] : [
'@nuxtjs/pwa',
'@nuxtjs/axios'
],
axios: { axios: {
proxy: true baseURL: 'https://api.hnpwa.com/v0/'
}, },
proxy: {
'/api': { plugins: [
target: 'https://api.hnpwa.com/v0/', '~/plugins/filters'
pathRewrite: { '^/api/': '' } ],
}
},
plugins: ['~/plugins/filters'],
serverMiddleware: ['~/common/cache.js'],
render: { render: {
http2: { http2: {
push: true push: true
......
{ {
"private": true,
"name": "nuxt-hn", "name": "nuxt-hn",
"description": "Nuxt Hacker News", "description": "Nuxt Hacker News",
"version": "1.0.0", "version": "1.0.0",
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
"name": "Pooya Parsa (@pi0)" "name": "Pooya Parsa (@pi0)"
} }
], ],
"private": true,
"scripts": { "scripts": {
"dev": "nuxt dev", "dev": "nuxt dev",
"build": "nuxt build", "build": "nuxt build",
...@@ -25,21 +25,15 @@ ...@@ -25,21 +25,15 @@
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"lintfix": "eslint --fix --ext .js,.vue --ignore-path .gitignore ." "lintfix": "eslint --fix --ext .js,.vue --ignore-path .gitignore ."
}, },
"now": {
"alias": "hn.nuxtjs.org"
},
"engines": { "engines": {
"node": ">=8.0" "node": ">=8.0"
}, },
"dependencies": { "dependencies": {
"@nuxtjs/axios": "^5.3.0", "@nuxtjs/axios": "^5.3.0",
"@nuxtjs/component-cache": "^1.1.1",
"@nuxtjs/pwa": "3.0.0-beta.8",
"apicache": "^1.2.1",
"express": "^4.16.3",
"nuxt-edge": "^2.5.0-25848007.21b1b865" "nuxt-edge": "^2.5.0-25848007.21b1b865"
}, },
"devDependencies": { "devDependencies": {
"@nuxtjs/pwa": "3.0.0-beta.8",
"@nuxtjs/eslint-config": "^0.0.1", "@nuxtjs/eslint-config": "^0.0.1",
"babel-eslint": "^10.0.1", "babel-eslint": "^10.0.1",
"eslint": "^5.14.1", "eslint": "^5.14.1",
......
...@@ -44,14 +44,14 @@ export default { ...@@ -44,14 +44,14 @@ export default {
computed: { computed: {
id() { id() {
return this.$route.params.id return this.$route.query.id
}, },
item() { item() {
return this.$store.state.items[this.id] return this.$store.state.items[this.id]
} }
}, },
fetch({ store, params: { id } }) { fetch({ store, query: { id } }) {
return store.dispatch('FETCH_ITEM', { id }) return store.dispatch('FETCH_ITEM', { id })
} }
} }
......
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
commit('SET_ITEMS', { items }) commit('SET_ITEMS', { items })
}, },
() => () =>
this.$axios.$get(`/api/${feed}/${page}.json`, { this.$axios.$get(`/${feed}/${page}.json`, {
cancelToken: this.feedCancelSource && this.feedCancelSource.token cancelToken: this.feedCancelSource && this.feedCancelSource.token
}), }),
(state.feeds[feed][page] || []).map(id => state.items[id]) (state.feeds[feed][page] || []).map(id => state.items[id])
...@@ -62,7 +62,7 @@ export default { ...@@ -62,7 +62,7 @@ export default {
FETCH_ITEM({ commit, state }, { id }) { FETCH_ITEM({ commit, state }, { id }) {
return lazy( return lazy(
item => commit('SET_ITEM', { item }), item => commit('SET_ITEM', { item }),
() => this.$axios.$get(`/api/item/${id}.json`), () => this.$axios.$get(`/item/${id}.json`),
Object.assign({ id, loading: true, comments: [] }, state.items[id]) Object.assign({ id, loading: true, comments: [] }, state.items[id])
) )
}, },
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
FETCH_USER({ state, commit }, { id }) { FETCH_USER({ state, commit }, { id }) {
return lazy( return lazy(
user => commit('SET_USER', { id, user }), user => commit('SET_USER', { id, user }),
() => this.$axios.$get(`/api/user/${id}.json`), () => this.$axios.$get(`/user/${id}.json`),
Object.assign({ id, loading: true }, state.users[id]) Object.assign({ id, loading: true }, state.users[id])
) )
} }
......
...@@ -1157,13 +1157,6 @@ ...@@ -1157,13 +1157,6 @@
axios-retry "^3.1.1" axios-retry "^3.1.1"
consola "^1.4.4" consola "^1.4.4"
"@nuxtjs/component-cache@^1.1.1":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@nuxtjs/component-cache/-/component-cache-1.1.4.tgz#4015e0ab3499dbaac80866b47c62b9936fda41f8"
integrity sha512-6bQjzYBnbuJzAlUFCB17axlnTs98KUB2F8p0Q42SD9CYietGyjceFPEbAiFwShdQYm7qn6FR2z6JN71ilmHopg==
dependencies:
lru-cache "^5.1.1"
"@nuxtjs/eslint-config@^0.0.1": "@nuxtjs/eslint-config@^0.0.1":
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/@nuxtjs/eslint-config/-/eslint-config-0.0.1.tgz#3aeed1cc6a2e01331c7e6b56bfa7152ce8bb2d90" resolved "https://registry.yarnpkg.com/@nuxtjs/eslint-config/-/eslint-config-0.0.1.tgz#3aeed1cc6a2e01331c7e6b56bfa7152ce8bb2d90"
...@@ -1599,11 +1592,6 @@ anymatch@^2.0.0: ...@@ -1599,11 +1592,6 @@ anymatch@^2.0.0:
micromatch "^3.1.4" micromatch "^3.1.4"
normalize-path "^2.1.1" normalize-path "^2.1.1"
apicache@^1.2.1:
version "1.4.0"
resolved "https://registry.yarnpkg.com/apicache/-/apicache-1.4.0.tgz#3835fbe18717caca3a44cb6272d49b52cac30d3a"
integrity sha512-pX/Sf9q9HNzAC5F+hPgxt8v3eQVZkXL/+8HpAnrDJXFmma80F2aHAAeWTql3BsG87lc3T6A7CFPNWMTl97L/7Q==
aproba@^1.0.3, aproba@^1.1.1: aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment