Skip to content

Commit

Permalink
feat: remove hardcoded tile base URL, use proxy config instead
Browse files Browse the repository at this point in the history
This approach fixes the CORS errors with the tileset queries.
  • Loading branch information
laurigates committed Aug 23, 2024
1 parent a7fccbe commit dbdf770
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM node:21-alpine

ARG VITE_TILE_BASE_URL="https://dl2sa.blob.core.windows.net/public3d/katukuntotieto"

WORKDIR /app

COPY . .
Expand Down
7 changes: 3 additions & 4 deletions src/components/CesiumViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { LayerItemProps } from "./LayerItem.vue";
const store = useStateStore();
const prod = import.meta.env.PROD;
const TILE_BASE_URL = import.meta.env.VITE_TILE_BASE_URL;
console.log(`Tile base url (prod=${prod}): ${TILE_BASE_URL}`);
console.log(`Tile base url (prod=${prod})`);
onMounted(async () => {
// @ts-ignore
Expand Down Expand Up @@ -70,7 +69,7 @@ const addConditionLayers = (store: StoreType) => {
if (!layer.enabled) {
return;
}
Cesium.Cesium3DTileset.fromUrl(`${TILE_BASE_URL}/${layer.id}/tileset.json`, {
Cesium.Cesium3DTileset.fromUrl(`/tiles/${layer.id}/tileset.json`, {
debugWireframe: false,
showOutline: true,
enableShowOutline: true,
Expand Down Expand Up @@ -112,7 +111,7 @@ const addBuildings = (store: StoreType) => {
};
const addCenterlines = (store: StoreType, layer: LayerItemProps) => {
Cesium.Cesium3DTileset.fromUrl(`${TILE_BASE_URL}/centerline/tileset.json`, {}).then(lyr => {
Cesium.Cesium3DTileset.fromUrl(`/tiles/centerline/tileset.json`, {}).then(lyr => {
if (store.layers["centerline"]) {
return;
}
Expand Down
23 changes: 22 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@ import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import cesium from "vite-plugin-cesium";

// https://vitejs.dev/config/
export default defineConfig({
server: {
proxy: {
"/tiles": {
target: "https://dl2sa.blob.core.windows.net/public3d/katukuntotieto",
changeOrigin: true,
secure: false,
rewrite: (p) => p.replace(/^\/tiles/, ""),
},
},
cors: false,
},
preview: {
proxy: {
"/tiles": {
target: "https://dl2sa.blob.core.windows.net/public3d/katukuntotieto",
changeOrigin: true,
secure: false,
rewrite: (p) => p.replace(/^\/tiles/, ""),
},
},
cors: false,
},
plugins: [
vue({
script: {
Expand Down

0 comments on commit dbdf770

Please sign in to comment.