Add portal sub-path support (basePath /dashboards/laadpalen)
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
const MapDeck = dynamic(() => import("@/components/MapDeck"), { ssr: false });
|
||||
|
||||
const NL_BOUNDS: [number, number, number, number] = [3.31, 50.75, 7.21, 53.47];
|
||||
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
|
||||
function EmbedInner() {
|
||||
const params = useSearchParams();
|
||||
@@ -29,14 +30,14 @@ function EmbedInner() {
|
||||
const load = async () => {
|
||||
if (slug === "nederland") {
|
||||
const [p, f] = (await Promise.all([
|
||||
fetch("/data/nederland-passenger.geojson").then((r) => r.json()),
|
||||
fetch("/data/nederland-freight.geojson").then((r) => r.json()),
|
||||
fetch(`${BASE_PATH}/data/nederland-passenger.geojson`).then((r) => r.json()),
|
||||
fetch(`${BASE_PATH}/data/nederland-freight.geojson`).then((r) => r.json()),
|
||||
])) as CropoutData[];
|
||||
if (cancelled) return;
|
||||
setChargeFeatures([...(p.features as ChargeFeature[]), ...(f.features as ChargeFeature[])]);
|
||||
setBounds(NL_BOUNDS);
|
||||
} else {
|
||||
const crop = (await fetch(`/data/gemeenten/${slug}.geojson`).then((r) => r.json())) as CropoutData;
|
||||
const crop = (await fetch(`${BASE_PATH}/data/gemeenten/${slug}.geojson`).then((r) => r.json())) as CropoutData;
|
||||
if (cancelled) return;
|
||||
setChargeFeatures(crop.features.filter((f) => f.properties.type === "charge") as ChargeFeature[]);
|
||||
setBoundaryFeatures(crop.features.filter((f) => f.properties.type === "boundary") as BoundaryFeature[]);
|
||||
|
||||
+11
-8
@@ -34,6 +34,9 @@ const MapDeck = dynamic(() => import("@/components/MapDeck"), {
|
||||
});
|
||||
|
||||
const NL_BOUNDS: [number, number, number, number] = [3.31, 50.75, 7.21, 53.47];
|
||||
// Portal sub-path support: empty for the standalone deployment, set at build
|
||||
// time for the wegoze portal (e.g. "/dashboards/laadpalen").
|
||||
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const DEFAULT_SLUG = "utrecht";
|
||||
|
||||
export default function Home() {
|
||||
@@ -59,7 +62,7 @@ export default function Home() {
|
||||
|
||||
// Load the analysis choropleth dataset once.
|
||||
useEffect(() => {
|
||||
fetch("/data/derived/gemeente-metrics.geojson")
|
||||
fetch(`${BASE_PATH}/data/derived/gemeente-metrics.geojson`)
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((d: ChoroplethData | null) => d && setChoropleth(d))
|
||||
.catch(() => {});
|
||||
@@ -193,7 +196,7 @@ export default function Home() {
|
||||
|
||||
// Load municipalities once.
|
||||
useEffect(() => {
|
||||
fetch("/municipalities.json")
|
||||
fetch(`${BASE_PATH}/municipalities.json`)
|
||||
.then((r) => r.json())
|
||||
.then((data: Municipality[]) => {
|
||||
const sorted = data.sort((a, b) => {
|
||||
@@ -237,9 +240,9 @@ export default function Home() {
|
||||
const load = async () => {
|
||||
if (selectedMunicipality === "nederland") {
|
||||
const [pRes, fRes, provRes] = await Promise.all([
|
||||
fetch("/data/nederland-passenger.geojson"),
|
||||
fetch("/data/nederland-freight.geojson"),
|
||||
fetch("/data/provinces.geojson"),
|
||||
fetch(`${BASE_PATH}/data/nederland-passenger.geojson`),
|
||||
fetch(`${BASE_PATH}/data/nederland-freight.geojson`),
|
||||
fetch(`${BASE_PATH}/data/provinces.geojson`),
|
||||
]);
|
||||
const [p, f, prov] = (await Promise.all([pRes.json(), fRes.json(), provRes.json()])) as CropoutData[];
|
||||
if (cancelled) return;
|
||||
@@ -253,9 +256,9 @@ export default function Home() {
|
||||
setGemeenteName("Nederland");
|
||||
} else {
|
||||
const [cropRes, detRes, statusRes] = await Promise.all([
|
||||
fetch(`/data/gemeenten/${selectedMunicipality}.geojson`),
|
||||
fetch(`/data/gemeenten/${selectedMunicipality}.details.json`),
|
||||
fetch(`/data/status/${selectedMunicipality}.json`),
|
||||
fetch(`${BASE_PATH}/data/gemeenten/${selectedMunicipality}.geojson`),
|
||||
fetch(`${BASE_PATH}/data/gemeenten/${selectedMunicipality}.details.json`),
|
||||
fetch(`${BASE_PATH}/data/status/${selectedMunicipality}.json`),
|
||||
]);
|
||||
const crop = (await cropRes.json()) as CropoutData;
|
||||
const bundle = (await detRes.json()) as DetailBundle;
|
||||
|
||||
@@ -84,6 +84,7 @@ export default function AddressSearchInput({
|
||||
onAddressSelected,
|
||||
}: AddressSearchInputProps) {
|
||||
const [query, setQuery] = useState('');
|
||||
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || '';
|
||||
const [results, setResults] = useState<SearchResult[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [showDropdown, setShowDropdown] = useState(false);
|
||||
@@ -106,7 +107,7 @@ export default function AddressSearchInput({
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/geocode?q=${encodeURIComponent(searchQuery)}`
|
||||
`${BASE_PATH}/api/geocode?q=${encodeURIComponent(searchQuery)}`
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -152,7 +153,7 @@ export default function AddressSearchInput({
|
||||
|
||||
try {
|
||||
// Lookup full details for the selected address
|
||||
const response = await fetch(`/api/geocode?id=${encodeURIComponent(result.id)}`);
|
||||
const response = await fetch(`${BASE_PATH}/api/geocode?id=${encodeURIComponent(result.id)}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Address lookup failed');
|
||||
|
||||
@@ -3,8 +3,13 @@ import type { NextConfig } from "next";
|
||||
// Basemap (CartoDB Positron via MapLibre) hosts used by the client.
|
||||
const MAP_TILE_HOSTS = "https://basemaps.cartocdn.com https://*.basemaps.cartocdn.com";
|
||||
|
||||
// Opt-in sub-path support: empty for standalone/root deployments (unchanged),
|
||||
// set to e.g. "/dashboards/laadpalen" at build time for the wegoze portal.
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
compress: true,
|
||||
...(basePath ? { basePath } : {}),
|
||||
|
||||
async headers() {
|
||||
const securityHeaders = [
|
||||
|
||||
Reference in New Issue
Block a user