Compare commits

..

No commits in common. "fetch-test" and "main" have entirely different histories.

5 changed files with 5 additions and 84 deletions

View File

@ -1,6 +1,5 @@
// @ts-check
import { defineConfig } from 'astro/config';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
// https://astro.build/config
export default defineConfig({});

View File

@ -1,47 +0,0 @@
let base64 = require('base-64');
let url = 'http://eu.httpbin.org/basic-auth/user/passwd';
let username = 'user';
let password = 'passwd';
let headers = new Headers();
//headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));
fetch(url, {method:'GET',
headers: headers,
//credentials: 'user:passwd'
})
.then(response => response.json())
.then(json => console.log(json));
//.done();
headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64'));
npm install base-64 --save
import { encode } from "base-64";
const response = await fetch(URL, {
method: 'post',
headers: new Headers({
'Authorization': 'Basic ' + encode(username + ":" + password),
'Content-Type': 'application/json'
}),
body: JSON.stringify({
"PassengerMobile": "xxxxxxxxxxxx",
"Password": "xxxxxxx"
})
});
const posts = await response.json();
// space in "C ontent-Type"
const headers = {
"C ontent-Type": "text/xml",
"Breaking-Bad": "<3",
};
fetch("https://example.com/", { headers });

10
package-lock.json generated
View File

@ -8,9 +8,7 @@
"name": "astro-icinga",
"version": "0.0.1",
"dependencies": {
"astro": "^5.6.1",
"base-64": "^1.0.0",
"https": "^1.0.0"
"astro": "^5.6.1"
}
},
"node_modules/@astrojs/compiler": {
@ -2303,12 +2301,6 @@
"integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==",
"license": "BSD-2-Clause"
},
"node_modules/https": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg==",
"license": "ISC"
},
"node_modules/import-meta-resolve": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.1.0.tgz",

View File

@ -9,8 +9,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^5.6.1",
"base-64": "^1.0.0",
"https": "^1.0.0"
"astro": "^5.6.1"
}
}
}

View File

@ -1,32 +1,11 @@
---
import Welcome from '../components/Welcome.astro';
import Layout from '../layouts/Layout.astro';
import base64 from "base-64";
//let base64 = require('base-64');
let username = "astro";
let password = "astro"
let url = "https://192.168.200.11:5665/v1"
const headers = {
"Accept": "application/json",
"Authorization": "Basic " + base64.encode(username + ":" + password),
};
const response = await fetch(url, {headers, });
const data = await response.json();
// Welcome to Astro! Wondering what to do next? Check out the Astro documentation at https://docs.astro.build
// Don't want to use any of this? Delete everything in this file, the `assets`, `components`, and `layouts` directories, and start fresh.
---
<Layout>
<h1> Wilkommen bei Astro. </h1>
<ul>
<li>{ headers.Accept}</li>
<li>{ headers.Authorization }</li>
</ul>
<ul>
<li>{ data.results[0] }</li>
<li>{ response.status</li>
</ul>
<Welcome />
</Layout>