diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..38e2a1d --- /dev/null +++ b/.env.development @@ -0,0 +1,3 @@ + +BASE_URL=/ +DATABASE_PATH=db.local.json diff --git a/.gitignore b/.gitignore index 202c535..ce3dee4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules dist # Local files +.env *.local* # Editor directories and files diff --git a/README.md b/README.md index f73e454..3824ef9 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Sito con una bacheca di problemi e la possibilità di inviare soluzioni in markd Installare tutte le dipendenze con il package manager preferito di turno (ed in tal caso sostituire `npm` con ad esempio `pnpm` o `yarn`) ```bash shell +$ cp .env.development .env $ npm install ``` @@ -25,38 +26,4 @@ $ npm run serve # TODO -- Pagina profilo utente - - Lista soluzioni inviate (con stato delle soluzioni: approvate o rifiutate) - -- Pagina dell'admin - - Lista delle soluzioni non corrette - - Creazione nuovi problemi - -- DBv2 - - ```js - relations: [ - { - from: 'Solution' - name: 'for' - to: 'Problem' - entries: [ - ['LRLAH2NoLFQAQHQgz', '1'] - ['JzyiDnwRCrkpzLL8W', '1'] - ['FFYMJjP2yr4ohdmdT', '2'] - ['VFHTb8fSrLOkPNVFx', '2'] - ] - } - { - from: 'User' - name: 'owns' - to: 'Solution' - entries: [ - ['aziis98', 'LRLAH2NoLFQAQHQgz'] - ['aziis98', 'JzyiDnwRCrkpzLL8W'] - ['BachoSeven', 'FFYMJjP2yr4ohdmdT'] - ['BachoSeven', 'VFHTb8fSrLOkPNVFx'] - ] - } - ] - ``` \ No newline at end of file +- [ ] Autenticazione vera magari con OAuth dell'ateneo o Google \ No newline at end of file diff --git a/client/api.tsx b/client/api.tsx index f019cbe..2395681 100644 --- a/client/api.tsx +++ b/client/api.tsx @@ -1,10 +1,14 @@ +export function prependBaseUrl(route: string) { + return import.meta.env.BASE_URL + (route.startsWith('/') ? route.substring(1) : route) +} + export const server = { async get(url: string) { - const res = await fetch(url, { credentials: 'include' }) + const res = await fetch(prependBaseUrl(url), { credentials: 'include' }) return await res.json() }, async post(url: string, body?: T) { - const res = await fetch(url, { + const res = await fetch(prependBaseUrl(url), { method: 'POST', credentials: 'include', headers: { @@ -16,7 +20,7 @@ export const server = { return await res.json() }, async patch(url: string, body?: T) { - const res = await fetch(url, { + const res = await fetch(prependBaseUrl(url), { method: 'PATCH', credentials: 'include', headers: { diff --git a/client/components/Header.tsx b/client/components/Header.tsx index 238ad30..0dcbf69 100644 --- a/client/components/Header.tsx +++ b/client/components/Header.tsx @@ -1,5 +1,6 @@ import { Link } from 'preact-router/match' import { isAdministrator, User, UserRole } from '../../shared/model' +import { prependBaseUrl } from '../api' const ROLE_LABEL: Record = { ['admin']: 'Admin', @@ -15,7 +16,7 @@ type Props = { export const Header = ({ user, noLogin }: Props) => (