Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pikaratikka and upgrade dependencies #23

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:18-alpine

ENV WORK /opt/mappoc
ENV NODE_ENV=production
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This app is a pretty simple map application, that shows the routes of selected d
## Installation and development

Requirements
- node (v16 or newer preferred)
- node (v18 or newer preferred)
- yarn package manager

Create your own apikey for Digitransit (https://portal-dev-api.digitransit.fi)
Expand Down
43 changes: 5 additions & 38 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
const { mapValues, orderBy } = require('lodash');
const fs = require('node:fs');

const SECRETS_PATH = '/run/secrets/';

// Check each env var and see if it has a value in the secrets. In that case, use the
// secret value. Otherwise use the env var. Using sync fs methods for the sake of
// simplicity, since this will only run once when staring the app, sync is OK.
const secrets = (fs.existsSync(SECRETS_PATH) && fs.readdirSync(SECRETS_PATH)) || [];

const secretsEnv = mapValues(process.env, (value, key) => {
const matchingSecrets = secrets.filter(secretFile => secretFile.startsWith(key));

const currentSecret =
orderBy(
matchingSecrets,
secret => {
const secretVersion = parseInt(secret[secret.length - 1], 10);
return isNaN(secretVersion) ? 0 : secretVersion;
},
'desc',
)[0] || null;

const filepath = SECRETS_PATH + currentSecret;

if (fs.existsSync(filepath)) {
return (fs.readFileSync(filepath, { encoding: 'utf8' }) || '').trim();
}

return value;
});


module.exports = {
GRAPHQL_URL: secretsEnv.GRAPHQL_URL || '',
LINK_URL: secretsEnv.LINK_URL || '',
DIGITRANSIT_URL: secretsEnv.DIGITRANSIT_URL || '',
DIGITRANSIT_APIKEY: secretsEnv.DIGITRANSIT_APIKEY || '',
PORT: secretsEnv.PORT || '',
GRAPHQL_URL: process.env.GRAPHQL_URL || '',
LINK_URL: process.env.LINK_URL || '',
DIGITRANSIT_URL: process.env.DIGITRANSIT_URL || '',
DIGITRANSIT_APIKEY: process.env.DIGITRANSIT_APIKEY || '',
PORT: process.env.PORT || '',
}
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<meta charset="utf-8" />
<title>Linjakartta</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.js"></script>
<script src="https://unpkg.com/maplibre-gl@3.1.0/dist/maplibre-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.css"
href="https://unpkg.com/maplibre-gl@3.1.0/dist/maplibre-gl.css"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function fetchData(feature) {
}

const currentDate = moment().format("YYYY-MM-DD")
let map = new mapboxgl.Map({
let map = new maplibregl.Map({
container: "map",
center: [24.9384, 60.1699],
style: `style.json/${currentDate}`,
Expand Down Expand Up @@ -204,7 +204,7 @@ function setOnClickEvent() {
return dateBegin.isBefore(momentDate) && dateEnd.isAfter(momentDate)
})

new mapboxgl.Popup()
new maplibregl.Popup()
.setLngLat(e.lngLat)
.setHTML(filteredFeatures.map(renderFeature).join(""))
.addTo(map)
Expand Down Expand Up @@ -274,7 +274,7 @@ function searchCallback(res) {
map.setZoom(15)

clearMarkers()
markerList.push(new mapboxgl.Marker().setLngLat(coordinates).addTo(map))
markerList.push(new maplibregl.Marker().setLngLat(coordinates).addTo(map))
} else {
alert("Hakusi ei tuottanut tuloksia")
}
Expand Down Expand Up @@ -325,7 +325,7 @@ function updateMap() {
const datepickerdiv = document.getElementById("datepicker").value
moment.locale("fi")
const momentDate = moment(datepickerdiv, "L").format("YYYY-MM-DD")
map = new mapboxgl.Map({
map = new maplibregl.Map({
container: "map",
center: [24.9384, 60.1699],
style: `style.json/${momentDate}`,
Expand All @@ -341,4 +341,4 @@ elem.addEventListener("keypress", function(e) {
}
})

map.addControl(new mapboxgl.NavigationControl(), "top-left")
map.addControl(new maplibregl.NavigationControl(), "top-left")
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"hsl-map-style": "hsldevcom/hsl-map-style#master",
"lodash": "^4.17.21"
"hsl-map-style": "hsldevcom/hsl-map-style#master"
},
"devDependencies": {
"nodemon": "^2.0.22",
"prettier": "^2.8.7"
"nodemon": "^3.0.1",
"prettier": "^3.0.3"
}
}
Loading