deploy to gcloud

This commit is contained in:
polv committed 2020-12-16 14:13:51 +07:00
1 parent e4e364ae2a
commit 4b7252c15f
12 files changed
+189 -120

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/zsh
# current directory is always `.git/..` root
# echo $PWD
+19
View File
@@ -0,0 +1,19 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
# Node.js dependencies:
node_modules/
/scripts/
+20
View File
@@ -0,0 +1,20 @@
runtime: nodejs12
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
-72
View File
@@ -1,75 +1,3 @@
import type { ITheme } from '~/server/theme'
export const THEME: ITheme = JSON.parse(process.env.THEME!)
export async function api<T = any>(
url: string,
opts: RequestInit & {
params?: Record<string, any>
} = {}
): Promise<
| T
| {
error: {
statusCode: number
message: unknown
}
}
> {
if (!url.startsWith('/api')) {
return {
error: {
statusCode: 500,
message: 'malformed API route',
},
}
}
const baseURL = new URL(
typeof location !== 'undefined'
? location.origin
: `http://localhost:${process.env.PORT}`
)
baseURL.pathname = url
Object.entries(opts.params || {}).map(([k, v]) => {
if (v) {
/**
* Arrays will be comma separated, and empty strings will be discarded.
*/
baseURL.searchParams.set(k, v)
}
})
const r = await fetch(baseURL.href, opts)
try {
/**
* Does not rely on `r.ok`, but rather, errorhandler
*/
const data = await r.json()
/**
* Transform to Nuxt-compatible style
*/
if (data.error) {
return {
error: {
statusCode: r.status,
message: data,
},
}
}
return data
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
}
return {
error: {
statusCode: r.status,
message: r,
},
}
}
+7 -2
View File
@@ -1,4 +1,5 @@
import { NuxtConfig } from '@nuxt/types'
import { getTheme } from './server/theme'
const config = async (): Promise<NuxtConfig> => {
@@ -54,7 +55,11 @@ const config = async (): Promise<NuxtConfig> => {
css: [],
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: ['~/plugins/format.ts', '~/plugins/remark42.client.js'],
plugins: [
'~/plugins/axios-fix.ts',
'~/plugins/format.ts',
'~/plugins/remark42.client.js',
],
// Auto import components (https://go.nuxtjs.dev/config-components)
components: true,
@@ -66,7 +71,7 @@ const config = async (): Promise<NuxtConfig> => {
],
// Modules (https://go.nuxtjs.dev/config-modules)
modules: [],
modules: ['@nuxtjs/axios'],
// Build Configuration (https://go.nuxtjs.dev/config-build)
build: {},
+2 -1
View File
@@ -14,6 +14,7 @@
},
"dependencies": {
"@nuxt/typescript-runtime": "^2.0.0",
"@nuxtjs/axios": "^5.12.4",
"@patarapolw/scope-css": "^1.3.0",
"@types/express": "^4.17.9",
"@types/js-yaml": "^3.12.5",
@@ -25,6 +26,7 @@
"js-yaml": "^3.14.1",
"morgan": "^1.10.0",
"nuxt": "^2.14.6",
"nuxt-property-decorator": "^2.8.8",
"showdown": "^1.9.1",
"zod": "^1.11.11"
},
@@ -49,7 +51,6 @@
"eslint-plugin-prettier": "^3.1.4",
"import-sort-parser-typescript": "^6.0.0",
"nodejieba": "^2.5.1",
"nuxt-property-decorator": "^2.8.8",
"prettier": "^2.1.2",
"ts-node": "^9.1.1",
"typescript": "4.0.5"
+1 -7
View File
@@ -9,7 +9,6 @@
<script lang="ts">
import { Vue, Component } from 'nuxt-property-decorator'
import { api } from '~/assets/global'
@Component<BlogPage>({
watch: {
@@ -17,18 +16,13 @@ import { api } from '~/assets/global'
'$route.query.page': '$fetch',
},
async fetch() {
const { result, count, error } = await api('/api/q', {
const { result, count } = await this.$axios.$get('/api/q', {
params: {
q: this.$route.query.q,
page: this.$route.query.page,
},
})
if (error) {
this.$nuxt.error(error)
return
}
this.posts = result
this.count = count
},
+24 -30
View File
@@ -47,36 +47,22 @@
</template>
<script lang="ts">
import { Vue, Component } from 'nuxt-property-decorator'
import { api, THEME } from '~/assets/global'
import { Vue, Component, Watch } from 'nuxt-property-decorator'
import { THEME } from '~/assets/global'
import '~/assets/remark42'
@Component<PostPage>({
async fetch() {
const r = await api('/api', {
const r = await this.$axios.$get('/api', {
params: {
path: this.$route.params.pathMatch,
},
})
if (r.error) {
this.$nuxt.error(r.error)
return
}
this.post = r
setTimeout(() => {
if (process.browser) {
if (window.REMARK42) {
this.initRemark42()
} else {
window.addEventListener('REMARK42::ready', () => {
this.initRemark42()
})
}
}
}, 1000)
},
mounted() {
this.initRemark42()
},
beforeDestroy() {
if (this.remark42Instance) {
@@ -99,18 +85,26 @@ export default class PostPage extends Vue {
remark42settings = THEME.comment?.remark42 || null
remark42Instance: any = null
@Watch('$fetchState.pending')
initRemark42() {
if (process.browser && this.remark42settings && window.REMARK42) {
if (this.remark42Instance) {
this.remark42Instance.destroy()
}
this.$nextTick(() => {
if (
this.$refs.remark42 &&
process.browser &&
this.remark42settings &&
window.REMARK42
) {
if (this.remark42Instance) {
this.remark42Instance.destroy()
}
this.remark42Instance = window.REMARK42.createInstance({
node: this.$refs.remark42 as HTMLElement,
host: this.remark42settings.host,
site_id: this.remark42settings.siteId,
})
}
this.remark42Instance = window.REMARK42.createInstance({
node: this.$refs.remark42 as HTMLElement,
host: this.remark42settings.host,
site_id: this.remark42settings.siteId,
})
}
})
}
}
</script>
+1 -7
View File
@@ -6,7 +6,6 @@
<script lang="ts">
import { Vue, Component } from 'nuxt-property-decorator'
import { api } from '~/assets/global'
@Component<TagPage>({
watch: {
@@ -14,7 +13,7 @@ import { api } from '~/assets/global'
'$route.query.page': '$fetch',
},
async fetch() {
const { result, count, error } = await api('/api/q', {
const { result, count } = await this.$axios.$get('/api/q', {
params: {
q: this.$route.query.q,
page: this.$route.query.page,
@@ -22,11 +21,6 @@ import { api } from '~/assets/global'
},
})
if (error) {
this.$nuxt.error(error)
return
}
this.posts = result
this.count = count
},
+31
View File
@@ -0,0 +1,31 @@
import { Plugin } from '@nuxt/types'
const plugin: Plugin = ({ $axios, error }) => {
if (typeof location !== 'undefined') {
$axios.defaults.baseURL = location.origin
}
$axios.interceptors.response.use(
(r) => {
if (r.data?.error) {
error({
statusCode: r.status,
message: r.data.error,
})
throw new Error(r.data.error)
}
return r
},
(err) => {
error({
statusCode: err.response.status,
message: err.toJSON(),
})
return Promise.reject(err)
}
)
}
export default plugin
+1 -1
View File
@@ -15,7 +15,7 @@
"~/*": ["./*"],
"@/*": ["./*"]
},
"types": ["@types/node", "@nuxt/types"]
"types": ["@types/node", "@nuxt/types", "@nuxtjs/axios"]
},
"exclude": ["node_modules", ".nuxt", "dist"]
}
+79
View File
@@ -1242,6 +1242,17 @@
webpack-node-externals "^2.5.2"
webpackbar "^4.0.0"
"@nuxtjs/axios@^5.12.4":
version "5.12.4"
resolved "https://registry.yarnpkg.com/@nuxtjs/axios/-/axios-5.12.4.tgz#596ed88441aaedc5e74349f34fff2a462b02d01c"
integrity sha512-NKDIkrhtteOwC163Qlglw7YyjWHfLecpC/wXax4Z2tVVDlYnvSBa1KGoH9AnDY30lfvi0gjBKWCcTnUY8PaWDA==
dependencies:
"@nuxtjs/proxy" "^2.1.0"
axios "^0.21.0"
axios-retry "^3.1.9"
consola "^2.15.0"
defu "^3.2.2"
"@nuxtjs/eslint-config-typescript@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@nuxtjs/eslint-config-typescript/-/eslint-config-typescript-3.0.0.tgz#4c307ba1d7038d3d4a6aa40ebd4e0bd80a9af512"
@@ -1273,6 +1284,13 @@
consola "^2.11.3"
eslint-loader "^4.0.2"
"@nuxtjs/proxy@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@nuxtjs/proxy/-/proxy-2.1.0.tgz#fa7715a11d237fa1273503c4e9e137dd1bf5575b"
integrity sha512-/qtoeqXgZ4Mg6LRg/gDUZQrFpOlOdHrol/vQYMnKu3aN3bP90UfOUB3QSDghUUK7OISAJ0xp8Ld78aHyCTcKCQ==
dependencies:
http-proxy-middleware "^1.0.6"
"@nuxtjs/youch@^4.2.3":
version "4.2.3"
resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed"
@@ -1458,6 +1476,13 @@
"@types/relateurl" "*"
"@types/uglify-js" "*"
"@types/http-proxy@^1.17.4":
version "1.17.4"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.4.tgz#e7c92e3dbe3e13aa799440ff42e6d3a17a9d045b"
integrity sha512-IrSHl2u6AWXduUaDLqYpt45tLVCtYv7o4Z0s1KghBCDgIIS9oW5K1H8mZG/A2CfeLdEa7rTd1ACOiHBc1EMT2Q==
dependencies:
"@types/node" "*"
"@types/integer@*":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/integer/-/integer-1.0.1.tgz#025d87e30d97f539fcc6087372af7d3672ffbbe6"
@@ -2288,6 +2313,20 @@ autoprefixer@^9.6.1:
postcss "^7.0.32"
postcss-value-parser "^4.1.0"
axios-retry@^3.1.9:
version "3.1.9"
resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.1.9.tgz#6c30fc9aeb4519aebaec758b90ef56fa03fe72e8"
integrity sha512-NFCoNIHq8lYkJa6ku4m+V1837TP6lCa7n79Iuf8/AqATAHYB0ISaAS1eyIenDOfHOLtym34W65Sjke2xjg2fsA==
dependencies:
is-retry-allowed "^1.1.0"
axios@^0.21.0:
version "0.21.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca"
integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==
dependencies:
follow-redirects "^1.10.0"
babel-eslint@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
@@ -4197,6 +4236,11 @@ etag@^1.8.1, etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
events@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379"
@@ -4522,6 +4566,11 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7"
integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==
for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -5046,6 +5095,26 @@ http-errors@~1.7.2:
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"
http-proxy-middleware@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-1.0.6.tgz#0618557722f450375d3796d701a8ac5407b3b94e"
integrity sha512-NyL6ZB6cVni7pl+/IT2W0ni5ME00xR0sN27AQZZrpKn1b+qRh+mLbBxIq9Cq1oGfmTc7BUq4HB77mxwCaxAYNg==
dependencies:
"@types/http-proxy" "^1.17.4"
http-proxy "^1.18.1"
is-glob "^4.0.1"
lodash "^4.17.20"
micromatch "^4.0.2"
http-proxy@^1.18.1:
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"
https-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
@@ -5434,6 +5503,11 @@ is-resolvable@^1.0.0:
resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88"
integrity sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==
is-retry-allowed@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4"
integrity sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==
is-ssh@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.2.tgz#a4b82ab63d73976fd8263cceee27f99a88bdae2b"
@@ -7970,6 +8044,11 @@ require-main-filename@^2.0.0:
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
reserved-words@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/reserved-words/-/reserved-words-0.1.2.tgz#00a0940f98cd501aeaaac316411d9adc52b31ab1"