Bundle network in front app and allow CORS in back
This commit is contained in:
parent
37a9a1bd72
commit
082270831d
|
@ -1,20 +1,16 @@
|
|||
const express = require('express');
|
||||
|
||||
const util = require('./util');
|
||||
const network = require('./data/network.json');
|
||||
const realtime = require('./data/realtime');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.use(express.static('dist'));
|
||||
const port = 4321;
|
||||
|
||||
app.get('/courses', async (req, res) =>
|
||||
{
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
const courses = await realtime.getCourses();
|
||||
return res.json(courses);
|
||||
});
|
||||
|
||||
app.get('/network', (req, res) => res.json(network));
|
||||
|
||||
app.listen(port, () => console.log(`App listening on port ${port}`));
|
||||
|
|
|
@ -21,15 +21,13 @@ const color = require('color');
|
|||
const mapboxToken = `pk.eyJ1IjoibWF0dGVvZGVsYWJyZSIsImEiOiJja2NxaTUyMmUwcmFhMn\
|
||||
h0NmFsdzQ3emxqIn0.cyxF0h36emIMTk3cc4VqUw`;
|
||||
|
||||
const server = window.origin;
|
||||
const network = require('../back/data/network.json');
|
||||
|
||||
const fetchDataSources = async () =>
|
||||
const makeDataSources = async () =>
|
||||
{
|
||||
const segmentsSource = new VectorSource();
|
||||
const stopsSource = new VectorSource();
|
||||
|
||||
const network = (await axios.get(`${server}/network`)).data;
|
||||
|
||||
segmentsSource.addFeatures(
|
||||
Object.values(network.lines).flatMap(({color, routes}) =>
|
||||
routes.map(({segments}) =>
|
||||
|
@ -105,7 +103,7 @@ const createMap = async (target) =>
|
|||
});
|
||||
|
||||
// Data overlay
|
||||
const {segmentsSource, stopsSource} = await fetchDataSources();
|
||||
const {segmentsSource, stopsSource} = await makeDataSources();
|
||||
|
||||
const segmentsBorderLayer = new VectorLayer({
|
||||
source: segmentsSource,
|
||||
|
|
Loading…
Reference in New Issue