Skip to content

Commit

Permalink
Introduce Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
akelsch committed Jun 10, 2020
1 parent 362e009 commit c9f6ea9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000
CMD [ "node", "server.js" ]
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.4'

services:
app:
build: .
ports:
- 3000:3000
postgres:
image: postgres
ports:
- 5432:5432
environment:
# - POSTGRES_USER=postgres
- POSTGRES_PASSWORD=mysecretpassword
# - POSTGRES_DB: postgres
19 changes: 10 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as fs from 'fs'
import * as http from 'http'
import * as path from 'path'
import * as querystring from 'querystring'
import { mapData } from './map-data.js'
// import { mapData } from './map-data.js'
import { douglasPeucker, webMercator } from './algorithms.js'

const hostname = '127.0.0.1'
const port = 3000
const HOST = '0.0.0.0'
const PORT = 3000

let rootDir

Expand All @@ -21,8 +21,8 @@ if (process.argv.length === 2) {
process.exit(2)
}

http.createServer(handleRequest).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
http.createServer(handleRequest).listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}/`)
})

function handleRequest (request, response) {
Expand All @@ -47,10 +47,11 @@ function handleRequest (request, response) {
function serveGeodata (response, queryParams) {
const { BL_ID: stateId, resolution, zoom } = queryParams

const geodata = mapData.features.filter(elem => elem.attributes.BL_ID === stateId || stateId === '0')
.flatMap(elem => elem.geometry.rings)
.map(ring => ring.map(([long, lat]) => webMercator(long, lat, zoom)))
.map(ring => applyResolution(ring, resolution))
// const geodata = mapData.features.filter(elem => elem.attributes.BL_ID === stateId || stateId === '0')
// .flatMap(elem => elem.geometry.rings)
// .map(ring => ring.map(([long, lat]) => webMercator(long, lat, zoom)))
// .map(ring => applyResolution(ring, resolution))
const geodata = {}

response.setHeader('Content-Type', 'application/json')
response.end(JSON.stringify(geodata))
Expand Down

0 comments on commit c9f6ea9

Please sign in to comment.