Skip to content

Commit

Permalink
fix: proxy images, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Mar 1, 2020
1 parent 41d879d commit cfac03a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/@guijs/frontend-core/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ VUE_APP_GUIJS_DEV=true
VUE_APP_GRAPHQL_BASE_URL=http://localhost:5000/graphql
VUE_APP_GRAPHQL_WS_URL=ws://localhost:5000/subscriptions
VUE_APP_TERMINAL_WS_URL=ws://localhost:5010
VUE_APP_PROXY=http://localhost:5000/_proxy
VUE_APP_AWESOME_URL=http://localhost:8080
1 change: 1 addition & 0 deletions packages/@guijs/frontend-core/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ VUE_APP_AWESOME_URL=https://awesomejs.dev
VUE_APP_GRAPHQL_BASE_URL=http://localhost:5910/graphql
VUE_APP_GRAPHQL_WS_URL=ws://localhost:5910/subscriptions
VUE_APP_TERMINAL_WS_URL=ws://localhost:5911
VUE_APP_PROXY=http://localhost:5910/_proxy
DISABLE_PURGECSS=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { ref, watch } from '@vue/composition-api'
import genericLogo from '@/assets/package.png'
import { proxy } from '@/util/proxy'
const cache = {}
Expand Down Expand Up @@ -57,6 +58,7 @@ export default {
src,
genericLogo,
onError,
proxy,
}
},
}
Expand All @@ -65,9 +67,9 @@ export default {
<template>
<div class="flex items-center justify-center">
<img
:src="src || pkg.defaultLogo || genericLogo"
:src="src || pkg.defaultLogo ? proxy(src || pkg.defaultLogo) : genericLogo"
:alt="`${pkg.id} logo`"
class="max-w-full max-h-full rounded overflow-hidden"
class="max-w-full max-h-full rounded overflow-hidden text-transparent"
@error="onError()"
>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import { ref, watch } from '@vue/composition-api'
import { ref, watch, computed } from '@vue/composition-api'
import { proxy } from '@/util/proxy'
export default {
props: {
Expand All @@ -18,10 +19,16 @@ export default {
loaded.value = false
})
const url = computed(() => {
const logo = props.projectType.logo
if (props.projectType.id.startsWith('__')) return logo
return proxy(logo)
})
watch(error, value => {
if (value) {
const img = new Image()
img.src = props.projectType.logo
img.src = url.value
img.onload = () => {
error.value = false
}
Expand All @@ -31,6 +38,7 @@ export default {
return {
error,
loaded,
url,
}
},
}
Expand All @@ -39,9 +47,9 @@ export default {
<template>
<img
:key="projectType.logo"
:src="error ? require('@/assets/box.svg') : projectType.logo"
:src="error ? require('@/assets/box.svg') : url"
:class="{
'bg-gray-200 dark:bg-gray-950 rounded': !loaded,
'bg-gray-200 dark:bg-gray-950 rounded text-transparent': !loaded,
}"
alt="Logo"
@error="error = true"
Expand Down
3 changes: 3 additions & 0 deletions packages/@guijs/frontend-core/src/util/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function proxy (url) {
return `${process.env.VUE_APP_PROXY}/${encodeURIComponent(url)}`
}
1 change: 1 addition & 0 deletions packages/@guijs/server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"os-locale": "^4.0.0",
"portfinder": "^1.0.25",
"resolve": "^1.15.1",
"request": "^2.88.2",
"shell-env": "^3.0.0",
"shortid": "^2.2.15",
"string_decoder": "^1.3.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/@guijs/server-core/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolveModule } from '@nodepack/module'
import express from 'express'
import fallback from 'express-history-api-fallback'
import path from 'path'
import request from 'request'
import Context from './generated/context'

const CACHE_CONTROL = 'no-store, no-cache, must-revalidate, private'
Expand All @@ -13,6 +14,14 @@ distPath = path.join(path.dirname(distPath), 'dist')

hook('expressHttp', (ctx: Context) => {
const app = ctx.express

// Proxy
app.get('/_proxy/:url', async (req, res) => {
const url = req.params.url
request(url).pipe(res)
})

// Assets
app.use(express.static(distPath, { setHeaders }))
app.use(fallback(path.join(distPath, 'index.html'), {
headers: {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14010,7 +14010,7 @@ [email protected]:
tunnel-agent "^0.6.0"
uuid "^3.3.2"

request@^2.87.0, request@^2.88.0:
request@^2.87.0, request@^2.88.0, request@^2.88.2:
version "2.88.2"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3"
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
Expand Down Expand Up @@ -15248,10 +15248,10 @@ tar@^6.0.0, tar@^6.0.1:
mkdirp "^1.0.3"
yallist "^4.0.0"

tauri@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/tauri/-/tauri-0.4.2.tgz#b90664c3e314e8c578f98bb0f534c6b4064fe13c"
integrity sha512-zDu3rirrxi6QgA+WJfJpkWwcPqTNolW/XQt3PUh5coaR+0lxq3wz1GDT7K3FcTTsHhK1B05SJU4DdNWUBwMLDA==
tauri@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/tauri/-/tauri-0.4.4.tgz#3ee842b6a9ec0ad4ccba49b0c86993d9df9db966"
integrity sha512-52Q3c7H76LGzWwg/OgqjCm1m24kqnpgqNl+I91biET3R5bH1o8LzHgvZAzZLgZGj06hquswzdaRVQUZxxIlLTw==
dependencies:
"@tauri-apps/tauri-inliner" "1.14.0"
"@tauri-apps/toml" "2.2.4"
Expand Down

0 comments on commit cfac03a

Please sign in to comment.