Skip to content

Commit

Permalink
✨ [feat/maps] #3 add map integration for production
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGFx committed Jan 8, 2021
1 parent bacb129 commit b93d3c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
22 changes: 0 additions & 22 deletions server.dev/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,10 @@ app.use( '/maps', express.static( path.resolve( __dirname, '../../maps' ) ) );

// ---

//io.listen( port, () => {
// const url = `localhost:${ port }`;
// const data = {
// url: url,
// port: port
// };
// const eventName = 'server.listen';
// const txt = `Euro Truck Simulator 2 dashboard is running at http://${ url }/`;
// io.emit( 'log', {
// eventName: eventName,
// rawData: data
// } );
// console.log( `[${ eventName }] ${ txt }` );
//} );

io.on( 'connection', socket => {
const data = fs.readFileSync( dateFilename );
console.log( 'Update' );
setInterval( () => io.emit( 'update', JSON.parse( data.toString() ) ), interval() );
//io.emit( 'update', JSON.parse( data.toString() ) );
} );

server.listen( port, () => {
Expand All @@ -73,13 +57,7 @@ server.listen( port, () => {
port: port
};

// const url = `localhost:${ port }`;
// const data = {
// url: url,
// port: port
// };
const eventName = 'server.listen';
//const txt = `Euro Truck Simulator 2 dashboard is running at http://${ url }/`;
io.emit( 'log', {
eventName: eventName,
rawData: data
Expand Down
11 changes: 10 additions & 1 deletion server/src/helpers/server.helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import fs from 'fs';
import http from 'http';
import path from 'path';
import socketio from 'socket.io';
import cors from 'cors';
import truckSimTelemetry from 'trucksim-telemetry';
import { logIt } from './utils.helpers';

let app, server, io, telemetry, port, config, interval, pathDist;
let app, server, io, telemetry, port, config, interval, pathDist, pathMap;
const configFilePath = path.resolve( process.cwd(), './config.ets2-dashboard-skin.json' );

const init = () => {
Expand All @@ -33,10 +34,18 @@ const init = () => {
: 15;
};
pathDist = path.resolve( __dirname, '../../../dist' );
pathMap = path.resolve( process.cwd(), './maps' );

app.use( bodyParser.json() );
app.use( cors( {
origin: /http:\/\/localhost:\d+/,
credentials: true
} ) );
app.use( express.static( pathDist ) );

if ( fs.existsSync( pathMap ) )
app.use( '/maps', express.static( pathMap ) );

app.post( '/config', ( req, res ) => {
fs.writeFileSync( configFilePath, JSON.stringify( req.body, null, 2 ) );

Expand Down

0 comments on commit b93d3c6

Please sign in to comment.