From fbd80998d024ba0f2f8975de8dfe8ebb976f19db Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Thu, 9 Sep 2021 09:00:39 -0400 Subject: [PATCH] feat: initial commit copied from git@github.com:dancesWithCycles/protobufjs-playground.git --- .env | 4 ++++ index.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 18 ++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 .env create mode 100644 index.js create mode 100644 package.json diff --git a/.env b/.env new file mode 100644 index 0000000..22a4839 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +NODE_ENV=development +URL=https://api.goswift.ly/real-time/rtamaryland/gtfs-rt-vehicle-positions +TOKEN=d404373607b6b6edc72fff62d06373ca + diff --git a/index.js b/index.js new file mode 100644 index 0000000..2f8b845 --- /dev/null +++ b/index.js @@ -0,0 +1,61 @@ +require('dotenv').config(); +const axios = require('axios'); +const debug=require('debug')('axios'); + +const URL=process.env.URL||'https://dedriver.org/gtfs/realtime'; +debug('URL: '+URL) + +const TOKEN=process.env.TOKEN||'TOKEN'; +debug('TOKEN: '+TOKEN) + +run().catch(err => { + debug('run: error') + console.log(err) +}); + +async function run() { + debug('run:...') + + + //HTTP GET + let dataGet = await axios.get( + //'https://dedriver.org/gtfs/realtime', + URL, + //'http://67.212.79.244:8080/hermes_st_Transcollines/pb/vehiclePositions.pb', + //'https://dedriver.org/gtfs-rt/vehiclePostions.pb', + //'http://localhost:3000/user', + { + headers:{ + 'accept':'application/octet-stream', + 'authorization':`${TOKEN}` + //'authorization':`Basic ${TOKEN}` + } + } + ) + .then(res => res.data); + debug('data received via GET'); + debug('dataGet len: %s',dataGet.length) + +/* + //HTTP POST + + //url as first, + //request body as second and + //options as third POST argument + //response is returned + const res=await axios.post( + 'http://localhost:3000/user', + //'https://dedriver.org/gtfs/realtime', + encodedPost, + { + headers:{ + 'content-type':'application/octet-stream'} + // 'content-type':'application/x-protobuf'} + //'transformRequest':[] + } + ).then(res => res.data); + debug('POST sent'); + debug('res JSON: %s',JSON.stringify(res)); + //debug('res content-type: %s',res.data.headers['content-type']); +*/ +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b77f342 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "axios", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Stefan Begerad", + "license": "GPL-3.0", + "devDependencies": { + "nodemon": "^2.0.7" + }, + "dependencies": { + "axios": "^0.21.1", + "dotenv": "^8.2.0" + } +}