mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
fix: lower vulnerabilities + harden docker setup
also includes a github workflow
This commit is contained in:
@@ -10,7 +10,13 @@ RUN npm run build
|
||||
|
||||
FROM node:20-alpine as runner
|
||||
WORKDIR /app
|
||||
COPY --from=build /app .
|
||||
RUN apk add --no-cache wget
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=5173
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --omit=dev --ignore-scripts && apk add --no-cache wget
|
||||
COPY --from=build --chown=node:node /app/build ./build
|
||||
RUN chown -R node:node /app
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "5173"]
|
||||
USER node
|
||||
CMD ["node", "build"]
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: LayoutServerLoad = async ({ fetch, url }) => {
|
||||
try {
|
||||
const res = await fetch('/api/auth/info');
|
||||
const pasteOptionsRes = await fetch('/api/paste/info');
|
||||
const options = await res.json();
|
||||
const pasteOptions = await pasteOptionsRes.json();
|
||||
return { options, pasteOptions, url: url.href };
|
||||
} catch {
|
||||
return { options: null, pasteOptions: null, url: url.href };
|
||||
const res = await fetch('/api/auth/info');
|
||||
const pasteOptionsRes = await fetch('/api/paste/info');
|
||||
|
||||
if (!res.ok || !pasteOptionsRes.ok) {
|
||||
throw error(503, 'Failed to load site configuration.');
|
||||
}
|
||||
|
||||
const options = await res.json();
|
||||
const pasteOptions = await pasteOptionsRes.json();
|
||||
return { options, pasteOptions, url: url.href };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { apiUrl } from '$lib/server/api';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export const GET = async () => {
|
||||
const res = await fetch(`${apiUrl}/health`);
|
||||
|
||||
if (!res.ok) {
|
||||
return json({ status: 'unhealthy', backend: res.status }, { status: 503 });
|
||||
}
|
||||
|
||||
return json({ status: 'ok' });
|
||||
};
|
||||
@@ -15,10 +15,14 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
}
|
||||
const content = await res.text();
|
||||
return new Response(content, {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8'
|
||||
}
|
||||
const responseHeaders = new Headers(res.headers);
|
||||
responseHeaders.delete('content-encoding');
|
||||
responseHeaders.delete('content-length');
|
||||
responseHeaders.delete('transfer-encoding');
|
||||
|
||||
return new Response(await res.arrayBuffer(), {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
headers: responseHeaders
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,17 +4,12 @@ import { extractError } from '$lib/utils/misc';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, request }) => {
|
||||
try {
|
||||
const headers = new Headers(request.headers);
|
||||
const res = await fetch('/api/paste/recent', { headers });
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw error(res.status, errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { recentPastes: [] };
|
||||
const headers = new Headers(request.headers);
|
||||
const res = await fetch('/api/paste/recent', { headers });
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw error(res.status, errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user