sokko-g/vite.config.js
Shinuwa bec9ea5b2f
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m39s
Validate and deploy Sokko G / deploy (push) Successful in 12s
Send a toolbox through an encrypted link
Sharing a toolbox meant exporting a JSON file and passing it around by
hand. A toolbox can now be sent from the site while staying local first:
the browser compresses and encrypts the v2 export with AES-GCM, and the
key lives only in the link fragment, so the server keeps for at most
24 hours a copy it cannot read.

- Add the /api/shares service: upload, metadata, download and revoke,
  with files in SHARES_DIR, a purge every 10 minutes, and single-use
  links (the default) deleted only once fully downloaded.
- Cap the server load: 50 MiB per share, total storage, free disk
  space, daily volume, concurrent and stalled uploads, reads per link,
  plus a wide per-connection cap kept in memory without storing IPs.
- Limit each browser to 2 shares and 100 MiB per day and 2 active
  links, and show the existing link of a toolbox already shared.
- Add the send dialog (card and game drawer) and the /receive page,
  which previews or directly imports through the existing import path.
- Move shared HTTP helpers to services/http.js for both APIs.
- Document the format, delivery, server layout and privacy wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:26:05 +01:00

64 lines
2.3 KiB
JavaScript

// Rôle : configure Vite et charge les variables locales communes au serveur.
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { loadProjectEnv } from "./scripts/load-project-env.mjs";
import { createCardsApiHandler } from "./services/cards/api.js";
import { createSharesApiHandler } from "./services/shares/api.js";
import { resolve } from "node:path";
loadProjectEnv();
// Le serveur de développement donne les droits administrateur à tout visiteur : il reste local sauf demande explicite.
const devHost = process.env.HOST || "127.0.0.1";
function nebulaCardsApi() {
return {
name: "nebula-cards-api",
apply: "serve",
configureServer(server) {
// Chaque page lit la configuration et la réserve : la suite E2E, depuis une seule adresse, dépasserait la limite par minute de production.
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: process.env.CARDS_ENABLED !== "false", devAuth: process.env.CARDS_DEV_AUTH !== "false", devPerks: true, apiRateLimit: 100_000 });
server.middlewares.use(async (req, res, next) => {
if (!await handler(req, res)) next();
});
server.httpServer?.once("close", handler.close);
}
};
}
function toolboxSharesApi() {
return {
name: "toolbox-shares-api",
apply: "serve",
configureServer(server) {
// Les plafonds par connexion sont levés : toute la suite E2E part de la même adresse. Les quotas du navigateur restent actifs.
const handler = createSharesApiHandler({
projectRoot: resolve("."),
enabled: process.env.SHARES_ENABLED !== "false",
limits: { ipDailyUploads: 100_000, ipDailyBytes: Number.MAX_SAFE_INTEGER, ipUploadsPerMinute: 100_000, readsPerMinute: 100_000, minFreeBytes: 0 }
});
server.middlewares.use(async (req, res, next) => {
if (!await handler(req, res)) next();
});
server.httpServer?.once("close", handler.close);
}
};
}
export default defineConfig({
root: "website",
publicDir: "public",
plugins: [react(), nebulaCardsApi(), toolboxSharesApi()],
server: {
host: devHost,
port: Number(process.env.PORT || 5173)
},
preview: {
host: devHost,
port: Number(process.env.PORT || 4173)
},
build: {
outDir: "dist",
emptyOutDir: true
}
});