diff --git a/astro.config.mjs b/astro.config.mjs index e762ba5..4b5b8fc 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,5 +1,6 @@ // @ts-check import { defineConfig } from 'astro/config'; +process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; // https://astro.build/config export default defineConfig({}); diff --git a/helper.txt b/helper.txt new file mode 100644 index 0000000..20fdbda --- /dev/null +++ b/helper.txt @@ -0,0 +1,47 @@ +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 }); + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a11df54..0cc8ffc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,9 @@ "name": "astro-icinga", "version": "0.0.1", "dependencies": { - "astro": "^5.6.1" + "astro": "^5.6.1", + "base-64": "^1.0.0", + "https": "^1.0.0" } }, "node_modules/@astrojs/compiler": { @@ -2301,6 +2303,12 @@ "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", diff --git a/package.json b/package.json index d7c9626..a208028 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.6.1" + "astro": "^5.6.1", + "base-64": "^1.0.0", + "https": "^1.0.0" } -} \ No newline at end of file +} diff --git a/src/pages/index.astro b/src/pages/index.astro index c04f360..0cf8801 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,11 +1,32 @@ --- -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. --- - +

Wilkommen bei Astro.

+ +