Fix API paths and make hotel name configurable

- /api/notices → /notices/api/notices to match nginx location block
  (was returning portal index.html causing JSON parse error)
- Add VITE_HOTEL_NAME build arg, remove hardcoded hotel name
- Add vite-env.d.ts for TypeScript import.meta.env support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-01 17:55:36 +00:00
parent e170adee12
commit 58b3d82b85
4 changed files with 16 additions and 5 deletions

View file

@ -3,6 +3,8 @@ WORKDIR /app
COPY package.json . COPY package.json .
RUN npm install RUN npm install
COPY . . COPY . .
ARG VITE_HOTEL_NAME="Number Four at Stow"
ENV VITE_HOTEL_NAME=$VITE_HOTEL_NAME
RUN npm run build RUN npm run build
FROM nginx:alpine FROM nginx:alpine

View file

@ -85,7 +85,7 @@ export function AuthGate({ children }: Props) {
Noticeboard Noticeboard
</h1> </h1>
<p style={{ color: 'var(--text-muted)', fontSize: '0.875rem', marginBottom: '1.5rem' }}> <p style={{ color: 'var(--text-muted)', fontSize: '0.875rem', marginBottom: '1.5rem' }}>
Hotel Number Four {import.meta.env.VITE_HOTEL_NAME}
</p> </p>
<form onSubmit={login} style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}> <form onSubmit={login} style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
<input <input

View file

@ -29,19 +29,19 @@ export function NoticeBoard({ user }: { user: User }) {
useEffect(() => { useEffect(() => {
const params = category !== 'all' ? `?category=${category}` : '' const params = category !== 'all' ? `?category=${category}` : ''
fetch(`/api/notices${params}`, { credentials: 'include' }) fetch(`/notices/api/notices${params}`, { credentials: 'include' })
.then(r => r.json()) .then(r => r.json())
.then(setNotices) .then(setNotices)
}, [category, forceRefresh]) }, [category, forceRefresh])
async function togglePin(id: number) { async function togglePin(id: number) {
await fetch(`/api/notices/${id}/pin`, { method: 'PATCH', credentials: 'include' }) await fetch(`/notices/api/notices/${id}/pin`, { method: 'PATCH', credentials: 'include' })
forceRefresh() forceRefresh()
} }
async function deleteNotice(id: number) { async function deleteNotice(id: number) {
if (!confirm('Delete this notice?')) return if (!confirm('Delete this notice?')) return
await fetch(`/api/notices/${id}`, { method: 'DELETE', credentials: 'include' }) await fetch(`/notices/api/notices/${id}`, { method: 'DELETE', credentials: 'include' })
forceRefresh() forceRefresh()
} }
@ -155,7 +155,7 @@ function PostForm({ onPosted }: { onPosted: () => void }) {
setSubmitting(true) setSubmitting(true)
setError('') setError('')
try { try {
const res = await fetch('/api/notices', { const res = await fetch('/notices/api/notices', {
method: 'POST', method: 'POST',
credentials: 'include', credentials: 'include',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },

9
frontend/src/vite-env.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_HOTEL_NAME: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}