1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-04 13:05:21 +02:00

fix recipe static routes

This commit is contained in:
hay-kot 2021-08-09 16:19:23 -08:00
parent 625dbcdea5
commit 8710dad727
11 changed files with 54 additions and 29 deletions

View file

@ -4,17 +4,6 @@ WORKDIR /app
COPY . . COPY . .
# Install Caddy
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
apt-transport-https \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add - \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
caddy
RUN yarn install \ RUN yarn install \
--prefer-offline \ --prefer-offline \
--frozen-lockfile \ --frozen-lockfile \
@ -35,13 +24,9 @@ FROM node:15-alpine
WORKDIR /app WORKDIR /app
# copying caddy into image # copying caddy into image
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY ./Caddyfile /app
COPY --from=builder /app . COPY --from=builder /app .
ENV HOST 0.0.0.0 ENV HOST 0.0.0.0
EXPOSE 3000 EXPOSE 3000
RUN ["caddy", "start", "--config", "/app/Caddyfile"]
CMD [ "yarn", "start" ] CMD [ "yarn", "start" ]

View file

@ -18,6 +18,7 @@
</template> </template>
<script> <script>
import { useStaticRoutes } from "~/composables/api";
import { useApiSingleton } from "~/composables/use-api"; import { useApiSingleton } from "~/composables/use-api";
export default { export default {
props: { props: {
@ -53,7 +54,9 @@ export default {
setup() { setup() {
const api = useApiSingleton(); const api = useApiSingleton();
return { api }; const { recipeImage, recipeSmallImage, recipeTinyImage } = useStaticRoutes();
return { api, recipeImage, recipeSmallImage, recipeTinyImage };
}, },
data() { data() {
return { return {
@ -77,11 +80,11 @@ export default {
getImage(slug) { getImage(slug) {
switch (this.imageSize) { switch (this.imageSize) {
case "tiny": case "tiny":
return this.api.recipes.recipeTinyImage(slug, this.imageVersion); return this.recipeTinyImage(slug, this.imageVersion);
case "small": case "small":
return this.api.recipes.recipeSmallImage(slug, this.imageVersion); return this.recipeSmallImage(slug, this.imageVersion);
case "large": case "large":
return this.api.recipes.recipeImage(slug, this.imageVersion); return this.recipeImage(slug, this.imageVersion);
} }
}, },
}, },

View file

@ -1,5 +1,5 @@
<template> <template>
<div v-if="recipes"> <div>
<v-app-bar v-if="!disableToolbar" color="transparent" flat class="mt-n1 flex-sm-wrap rounded"> <v-app-bar v-if="!disableToolbar" color="transparent" flat class="mt-n1 flex-sm-wrap rounded">
<v-icon v-if="title" large left> <v-icon v-if="title" large left>
{{ displayTitleIcon }} {{ displayTitleIcon }}
@ -139,7 +139,7 @@ export default {
}, },
recipes: { recipes: {
type: Array, type: Array,
required: true, default: () => [],
}, },
}, },
data() { data() {

View file

@ -0,0 +1 @@
export { useStaticRoutes } from "./static-routes";

View file

@ -0,0 +1,31 @@
import { useContext } from "@nuxtjs/composition-api";
export const useStaticRoutes = () => {
const { $config } = useContext();
const prefix = `${$config.SUB_PATH}/api`.replace("//", "/");
// Methods to Generate reference urls for assets/images *
function recipeImage(recipeSlug: string, version = null, key = null) {
return `${prefix}/media/recipes/${recipeSlug}/images/original.webp?&rnd=${key}&version=${version}`;
}
function recipeSmallImage(recipeSlug: string, version = null, key = null) {
return `${prefix}/media/recipes/${recipeSlug}/images/min-original.webp?&rnd=${key}&version=${version}`;
}
function recipeTinyImage(recipeSlug: string, version = null, key = null) {
return `${prefix}/media/recipes/${recipeSlug}/images/tiny-original.webp?&rnd=${key}&version=${version}`;
}
function recipeAssetPath(recipeSlug: string, assetName: string) {
return `${prefix}/media/recipes/${recipeSlug}/assets/${assetName}`;
}
return {
recipeImage,
recipeSmallImage,
recipeTinyImage,
recipeAssetPath,
};
};

View file

@ -28,7 +28,7 @@ import AppFloatingButton from "@/components/Layout/AppFloatingButton.vue";
export default defineComponent({ export default defineComponent({
components: { AppHeader, AppSidebar, AppFloatingButton }, components: { AppHeader, AppSidebar, AppFloatingButton },
// @ts-ignore // @ts-ignore
middleware: process.env.GLOBAL_MIDDLEWARE, // middleware: process.env.GLOBAL_MIDDLEWARE,
setup() { setup() {
return {}; return {};
}, },

View file

@ -198,6 +198,7 @@ export default {
publicRuntimeConfig: { publicRuntimeConfig: {
GLOBAL_MIDDLEWARE: process.env.GLOBAL_MIDDLEWARE || null, GLOBAL_MIDDLEWARE: process.env.GLOBAL_MIDDLEWARE || null,
ALLOW_SIGNUP: process.env.ALLOW_SIGNUP || true, ALLOW_SIGNUP: process.env.ALLOW_SIGNUP || true,
SUB_PATH: process.env.SUB_PATH || "",
axios: { axios: {
browserBaseURL: process.env.SUB_PATH || "", browserBaseURL: process.env.SUB_PATH || "",
}, },
@ -208,9 +209,9 @@ export default {
proxy: { proxy: {
// "http://localhost:9000/*/api", // "http://localhost:9000/*/api",
// See Proxy section // See Proxy section
[`${process.env.SUB_PATH}api`]: { [`${process.env.SUB_PATH || ""}api`]: {
pathRewrite: { pathRewrite: {
[`${process.env.SUB_PATH}api`]: "/api", // rewrite path [`${process.env.SUB_PATH || ""}api`]: "/api", // rewrite path
}, },
changeOrigin: true, changeOrigin: true,
target: process.env.API_URL || "http://localhost:9000", target: process.env.API_URL || "http://localhost:9000",
@ -268,7 +269,7 @@ export default {
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: { build: {
// https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build // https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build
analyze: true, analyze: process.env.NODE_ENV !== "production",
babel: { babel: {
plugins: [["@babel/plugin-proposal-private-property-in-object", { loose: true }]], plugins: [["@babel/plugin-proposal-private-property-in-object", { loose: true }]],
}, },

View file

@ -1,7 +1,6 @@
<template> <template>
<v-container> <v-container>
<RecipeCardSection <RecipeCardSection
v-if="recentRecipes"
:icon="$globals.icons.primary" :icon="$globals.icons.primary"
:title="$t('general.recent')" :title="$t('general.recent')"
:recipes="recentRecipes" :recipes="recentRecipes"
@ -13,12 +12,15 @@
import { defineComponent } from "@nuxtjs/composition-api"; import { defineComponent } from "@nuxtjs/composition-api";
import RecipeCardSection from "~/components/Domain/Recipe/RecipeCardSection.vue"; import RecipeCardSection from "~/components/Domain/Recipe/RecipeCardSection.vue";
import { useRecipes, recentRecipes } from "~/composables/use-recipes"; import { useRecipes, recentRecipes } from "~/composables/use-recipes";
import { useStaticRoutes } from "~/composables/api";
export default defineComponent({ export default defineComponent({
components: { RecipeCardSection }, components: { RecipeCardSection },
setup() { setup() {
const { assignSorted } = useRecipes(false); const { assignSorted } = useRecipes(false);
useStaticRoutes();
return { recentRecipes, assignSorted }; return { recentRecipes, assignSorted };
}, },
}); });

View file

@ -33,7 +33,7 @@
:key="imageKey" :key="imageKey"
:max-width="recipe.settings.landscapeView ? null : '50%'" :max-width="recipe.settings.landscapeView ? null : '50%'"
:height="hideImage ? '50' : imageHeight" :height="hideImage ? '50' : imageHeight"
:src="api.recipes.recipeImage(recipe.slug, imageKey)" :src="recipeImage(recipe.slug, imageKey)"
class="d-print-none" class="d-print-none"
@error="hideImage = true" @error="hideImage = true"
> >
@ -183,6 +183,7 @@ import RecipeNotes from "~/components/Domain/Recipe/RecipeNotes.vue";
import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue"; import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue";
import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue"; import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue";
import { Recipe } from "~/types/api-types/admin"; import { Recipe } from "~/types/api-types/admin";
import { useStaticRoutes } from "~/composables/api";
export default defineComponent({ export default defineComponent({
components: { components: {
@ -208,6 +209,8 @@ export default defineComponent({
const { getBySlug, loading } = useRecipeContext(); const { getBySlug, loading } = useRecipeContext();
const { recipeImage } = useStaticRoutes();
const recipe = getBySlug(slug); const recipe = getBySlug(slug);
const form = ref<boolean>(false); const form = ref<boolean>(false);
@ -250,6 +253,7 @@ export default defineComponent({
updateRecipe, updateRecipe,
uploadImage, uploadImage,
validators, validators,
recipeImage,
}; };
}, },
data() { data() {

View file

@ -1,7 +1,6 @@
<template> <template>
<v-container> <v-container>
<RecipeCardSection <RecipeCardSection
v-if="allRecipes"
:icon="$globals.icons.primary" :icon="$globals.icons.primary"
:title="$t('page.all-recipes')" :title="$t('page.all-recipes')"
:recipes="allRecipes" :recipes="allRecipes"

View file

@ -1,7 +1,6 @@
<template> <template>
<v-container> <v-container>
<RecipeCardSection <RecipeCardSection
v-if="category"
:icon="$globals.icons.tags" :icon="$globals.icons.tags"
:title="category.name" :title="category.name"
:recipes="category.recipes" :recipes="category.recipes"