главная страница
материалы
  ms access и bitmap
  win в ucs-2 на perl
  приложение facebook
  медиа библиотека
  восстановление exif
  netgear stora
  netgear stora usb
  html и javascript
  openwrt upgrade
  yandex dns
  playlist vbs
  фотоархив
  node.js
  изменения в mrtg
  windows
  конвертация
  перекодировка для tv
  перекодировка для tvix

Приложения в Node.js

Basic authorization

const http = require('http');
const port = 80;

const server = http.createServer((req, res) => {
  if (req.headers.authorization) {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.write('authorization: '+req.headers.authorization);
    res.end();
  } else {
    res.statusCode = 401;
    res.setHeader('WWW-Authenticate', 'Basic realm="node.js"');
    res.end('Unauthorized');
  }
})

server.listen(port,() => {
  console.log('server is running')
});

Функция в Yandex Cloud

const http = require('http');

function gethttp(router,url) {
var port = 0;
if (router == 'ap') port = порт ap;
if (router == 'ap-tvix') port = порт ap-tvix;
if (port > 0) {
  const options = {
    host: 'cholv.ru',
    headers: {Authorization: 'Basic code'},
    port: port,
    path: url
  };
  return new Promise((resolve, reject) => {
    http.request(options, (response) => {
      let data = '';
      response.on('data', (chunk) => {
        data += chunk;
      });
      response.on('end', () => {
        resolve(data);
      });
      response.on('error', (err) => {
        reject(err);
      });
    }).end();
  });
}}

module.exports.handler = async function (event, context) {
  let str = await gethttp('ap-tvix','/status');
  return(str);
};