Bundle network in front app and allow CORS in back

This commit is contained in:
Mattéo Delabre 2020-07-17 20:10:52 +02:00
parent 37a9a1bd72
commit 082270831d
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
2 changed files with 5 additions and 11 deletions

View File

@ -1,20 +1,16 @@
const express = require('express'); const express = require('express');
const util = require('./util'); const util = require('./util');
const network = require('./data/network.json');
const realtime = require('./data/realtime'); const realtime = require('./data/realtime');
const app = express(); const app = express();
const port = 3000; const port = 4321;
app.use(express.static('dist'));
app.get('/courses', async (req, res) => app.get('/courses', async (req, res) =>
{ {
res.header('Access-Control-Allow-Origin', '*');
const courses = await realtime.getCourses(); const courses = await realtime.getCourses();
return res.json(courses); return res.json(courses);
}); });
app.get('/network', (req, res) => res.json(network));
app.listen(port, () => console.log(`App listening on port ${port}`)); app.listen(port, () => console.log(`App listening on port ${port}`));

View File

@ -21,15 +21,13 @@ const color = require('color');
const mapboxToken = `pk.eyJ1IjoibWF0dGVvZGVsYWJyZSIsImEiOiJja2NxaTUyMmUwcmFhMn\ const mapboxToken = `pk.eyJ1IjoibWF0dGVvZGVsYWJyZSIsImEiOiJja2NxaTUyMmUwcmFhMn\
h0NmFsdzQ3emxqIn0.cyxF0h36emIMTk3cc4VqUw`; h0NmFsdzQ3emxqIn0.cyxF0h36emIMTk3cc4VqUw`;
const server = window.origin; const network = require('../back/data/network.json');
const fetchDataSources = async () => const makeDataSources = async () =>
{ {
const segmentsSource = new VectorSource(); const segmentsSource = new VectorSource();
const stopsSource = new VectorSource(); const stopsSource = new VectorSource();
const network = (await axios.get(`${server}/network`)).data;
segmentsSource.addFeatures( segmentsSource.addFeatures(
Object.values(network.lines).flatMap(({color, routes}) => Object.values(network.lines).flatMap(({color, routes}) =>
routes.map(({segments}) => routes.map(({segments}) =>
@ -105,7 +103,7 @@ const createMap = async (target) =>
}); });
// Data overlay // Data overlay
const {segmentsSource, stopsSource} = await fetchDataSources(); const {segmentsSource, stopsSource} = await makeDataSources();
const segmentsBorderLayer = new VectorLayer({ const segmentsBorderLayer = new VectorLayer({
source: segmentsSource, source: segmentsSource,