Skip to content

Commit

Permalink
Simplify demo - remove nginx (#692)
Browse files Browse the repository at this point in the history
This uses the webserver built into vitejs instead of configuring an
entirely new nginx server with an additional docker image.
  • Loading branch information
birkskyum authored May 30, 2023
1 parent 9f95e51 commit a8f7c30
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 114 deletions.
8 changes: 6 additions & 2 deletions demo/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ services:
context: ./frontend
dockerfile: Dockerfile
restart: unless-stopped
command: ["npm", "run", "preview"]
depends_on:
- tiles
ports:
- "80:80"
- "80:8080"

tiles:
image: urbica/martin
image: ghcr.io/maplibre/martin
# For Arm64 - you have to build your own image from source https://github.com/maplibre/martin/issues/655#issuecomment-1540669505
restart: unless-stopped
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://postgres@db/db
depends_on:
Expand Down
6 changes: 1 addition & 5 deletions demo/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ FROM node:18-alpine as builder
WORKDIR /usr/src/app
COPY . .
RUN npm i
RUN npm run build

FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=builder "/usr/src/app/dist" /usr/share/nginx/html
RUN npm run build
89 changes: 0 additions & 89 deletions demo/frontend/nginx.conf

This file was deleted.

4 changes: 2 additions & 2 deletions demo/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "vite --port 3000 --host",
"dev": "vite --port 8080 --host",
"build": "tsc && vite build",
"preview": "vite preview",
"preview": "vite preview --port 8080 --host",
"lint": "eslint src"
},
"eslintConfig": {
Expand Down
4 changes: 3 additions & 1 deletion demo/frontend/src/Components/Development/Development.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import React from 'react';
import Container from './Container';
import Title from './Title';
import GitHubButton from '../GitHubButton';
import DocsButton from '../GitHubButton/DocsButton';

const Development = () => (
<Container>
<Title>Start building with Martin!</Title>
<GitHubButton />
<GitHubButton />{' '}
<DocsButton />
</Container>
);

Expand Down
11 changes: 11 additions & 0 deletions demo/frontend/src/Components/GitHubButton/DocsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import octocat from './octocat.svg';
import Container from './Container';

const DocsButton = () => (
<Container href='https://maplibre.org/martin' target='_blank'>
<span>Documentation</span>
</Container>
);

export default DocsButton;
6 changes: 4 additions & 2 deletions demo/frontend/src/Components/Intro/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import Container from './Container'
import Title from './Title'
import Description from './Description'
import GitHubButton from '../GitHubButton'
import DocsButton from '../GitHubButton/DocsButton'

const Intro = () => (
<Container>
<Parallax translateY={[100, -50]}>
<Title>Martin</Title>
<Title>Martin<br />Demo</Title>
<Description>Vector Tiles from Large Databases on the Fly</Description>
<GitHubButton />
<GitHubButton />{' '}
<DocsButton />
</Parallax>
</Container>
)
Expand Down
7 changes: 4 additions & 3 deletions demo/frontend/src/Components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Map extends PureComponent<{}, {visibleLayer, range, hour}> {

componentDidMount() {
this.map = new maplibregl.Map({
cooperativeGestures: true,
container: 'map',
style: MAP_STYLE,
center: [-74.005308, 40.713370],
Expand All @@ -38,14 +39,14 @@ class Map extends PureComponent<{}, {visibleLayer, range, hour}> {
});
this.nav = new maplibregl.NavigationControl();

this.map.scrollZoom.disable();

this.map.addControl(this.nav, 'top-right');
this.map.on('load', this.mapOnLoad);
}

componentDidUpdate() {
const queryParams = this.getQueryParams();
const newStyleUrl = `/tiles/rpc/public.get_trips.json?${queryParams}`;
const newStyleUrl = `http://localhost:3000/get_trips?${queryParams}`;
const newStyle = this.map.getStyle();

newStyle.sources['public.get_trips'].url = newStyleUrl;
Expand All @@ -57,7 +58,7 @@ class Map extends PureComponent<{}, {visibleLayer, range, hour}> {

this.map.addSource('public.get_trips', {
type: 'vector',
url: `/tiles/rpc/public.get_trips.json?${queryParams}`
url: `http://localhost:3000/get_trips?${queryParams}`
});
layers.forEach(({ mapboxLayer }) => {
this.map.addLayer(mapboxLayer, 'place_town');
Expand Down
22 changes: 12 additions & 10 deletions demo/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mkcert from 'vite-plugin-mkcert'
import { resolve } from 'path'
import viteTsConfigPaths from 'vite-tsconfig-paths';
import viteTsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [react(), viteTsConfigPaths({
root: './',
}), mkcert()],
plugins: [
react(),
viteTsConfigPaths({
root: './',
}),
mkcert(),
],
build: {
target: 'esnext',

},
server: { https: true },
});
server: { https: false, host: true, port: 8080 },
})

0 comments on commit a8f7c30

Please sign in to comment.