add: deployment ready
This commit is contained in:
parent
29f0976f84
commit
5ca65c77cb
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,4 +23,5 @@ pnpm-debug.log*
|
||||
# jetbrains setting folder
|
||||
.idea/
|
||||
|
||||
photos/
|
||||
public/IMG/
|
||||
@ -3,7 +3,7 @@ WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN mkdir -p /app/public/IMG
|
||||
RUN mkdir -p /app/dist/client/IMG
|
||||
|
||||
RUN npm install
|
||||
|
||||
@ -13,6 +13,6 @@ ENV HOST=0.0.0.0
|
||||
ENV PORT=4321
|
||||
EXPOSE 4321
|
||||
|
||||
ENV PHOTO_DIR_ABSOLUTE_PATH=/app/public/IMG
|
||||
ENV PHOTO_DIR_ABSOLUTE_PATH=/app/dist/client/IMG
|
||||
|
||||
CMD ["node", "./dist/server/entry.mjs"]
|
||||
@ -6,4 +6,4 @@ services:
|
||||
ports:
|
||||
- "4321:4321"
|
||||
volumes:
|
||||
- ./photos:/app/public/IMG
|
||||
- ./photos:/app/dist/client/IMG
|
||||
|
||||
24
src/pages/IMG/[file].ts
Normal file
24
src/pages/IMG/[file].ts
Normal file
@ -0,0 +1,24 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { APIRoute } from "astro";
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const GET: APIRoute = ({ params }) => {
|
||||
const file = params.file;
|
||||
|
||||
const filePath = path.join(process.env.PHOTO_DIR_ABSOLUTE_PATH!, file!);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return new Response("Image introuvable", { status: 404 });
|
||||
}
|
||||
|
||||
const image = fs.readFileSync(filePath);
|
||||
|
||||
return new Response(image, {
|
||||
headers: {
|
||||
"Content-Type": "image/jpeg",
|
||||
"Cache-Control": "public, max-age=31536000",
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -6,6 +6,7 @@ import Layout from "../components/Layout.astro";
|
||||
import Image from "../components/Image.astro";
|
||||
import { initPhotos } from "../misc";
|
||||
import { PHOTO_DIR_ABSOLUTE_PATH } from "astro:env/server";
|
||||
export const prerender = false;
|
||||
|
||||
const imageFilenames = fs
|
||||
.readdirSync(PHOTO_DIR_ABSOLUTE_PATH)
|
||||
|
||||
@ -38,8 +38,6 @@ const p = initPhoto(
|
||||
Number(width),
|
||||
Number(height),
|
||||
);
|
||||
|
||||
console.log(tags);
|
||||
---
|
||||
|
||||
<Layout>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user