feat:adapted to example https://masteringjs.io/tutorials/axios/basic_auth
This commit is contained in:
parent
fbd80998d0
commit
06abf48a86
5
.env
5
.env
|
@ -1,4 +1,5 @@
|
|||
NODE_ENV=development
|
||||
URL=https://api.goswift.ly/real-time/rtamaryland/gtfs-rt-vehicle-positions
|
||||
TOKEN=d404373607b6b6edc72fff62d06373ca
|
||||
URL=https://test-tarifmatrix.vbn.de:4245/fares/info
|
||||
USR=USR
|
||||
KEY=KEY
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Stefan Begerad <stefan@begerad.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
# axios
|
||||
Client using axios library to send a HTTP GET request.
|
||||
|
||||
## Overview
|
||||
This repository provides a command line interface service for Linux based operating system.
|
||||
|
||||
## Preparation
|
||||
Run the following command in your favorite GNU/Linux shell to install dependenies.
|
||||
```
|
||||
npm i
|
||||
```
|
||||
## Development setup
|
||||
Run the following command in your favorite GNU/Linux shell if you fancy log messages for debugging.
|
||||
```
|
||||
export DEBUG=$DEBUG,axios
|
||||
```
|
||||
Run the following command in your favorite GNU/Linux shell to start the service in development mode.
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
## Production deployment
|
||||
Run the following command in your favorite GNU/Linux shell to start the service for production mode.
|
||||
```
|
||||
npm run start
|
||||
```
|
33
index.js
33
index.js
|
@ -2,11 +2,14 @@ require('dotenv').config();
|
|||
const axios = require('axios');
|
||||
const debug=require('debug')('axios');
|
||||
|
||||
const URL=process.env.URL||'https://dedriver.org/gtfs/realtime';
|
||||
const URL=process.env.URL||'https://tarifmatrix.vbn.de:4445/fares/info';
|
||||
debug('URL: '+URL)
|
||||
|
||||
const TOKEN=process.env.TOKEN||'TOKEN';
|
||||
debug('TOKEN: '+TOKEN)
|
||||
const USR=process.env.USR||'USR';
|
||||
debug('USR: '+USR)
|
||||
|
||||
const KEY=process.env.KEY||'KEY';
|
||||
debug('KEY: '+KEY)
|
||||
|
||||
run().catch(err => {
|
||||
debug('run: error')
|
||||
|
@ -19,22 +22,22 @@ async function 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}`
|
||||
{
|
||||
// Axios looks for the `auth` option, and, if it is set, formats a
|
||||
// basic auth header for you automatically.
|
||||
auth: {
|
||||
username: `${USR}`,
|
||||
password: `${KEY}`
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(res => res.data);
|
||||
});
|
||||
res.status; // 200
|
||||
|
||||
debug('data received via GET');
|
||||
debug('dataGet len: %s',dataGet.length)
|
||||
// debug('dataGet: %s',dataGet)
|
||||
debug('dataGet: %s',JSON.stringify(dataGet))
|
||||
// debug('res JSON: %s',JSON.stringify(res));
|
||||
|
||||
/*
|
||||
//HTTP POST
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"dev": "nodemon index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Stefan Begerad",
|
||||
"license": "GPL-3.0",
|
||||
|
|
Loading…
Reference in New Issue