How to use xhr2 - 10 common examples

To help you get started, we’ve selected a few xhr2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github patrickmichalina / fusing-angular-v1-archived / src / server / server.app.ts View on Github external
import { ngExpressEngine } from '@nguniversal/express-engine'
import { AppServerModule } from './angular/server.angular.module'
import { argv } from 'yargs'
import { resolve } from 'path'
import { rollbarInit } from './add-ons/rollbar'
import { useApi } from './rest-api/index'
import ms = require('ms')

const shrinkRay = require('shrink-rayed')
const minifyHTML = require('express-minify-html')
const bunyanMiddleware = require('bunyan-middleware')
const xhr2 = require('xhr2')
const cors = require('cors')

// tslint:disable-next-line:no-object-mutation
xhr2.prototype._restrictedHeaders.cookie = false

require('ts-node/register')

const app = express()
rollbarInit(app)
const isProd = argv['build-type'] === 'prod' || argv['prod']
const isEndToEndTest = argv.e2e

const staticOptions = {
  index: false,
  maxAge: isProd ? ms('1y') : ms('0'),
  setHeaders: (res: express.Response, path: any) => {
    res.setHeader(
      'Expires',
      isProd
        ? new Date(Date.now() + ms('1y')).toUTCString()
github aadsm / jsmediatags / src / XhrFileReader.js View on Github external
_createXHRObject(): XMLHttpRequest {
    if (typeof window === "undefined" && !this._isWebWorker()) {
      // $FlowIssue - flow is not able to recognize this module.
      return new (require("xhr2").XMLHttpRequest)();
    }

    if (typeof XMLHttpRequest !== "undefined") {
      return new XMLHttpRequest();
    }

    throw new Error("XMLHttpRequest is not supported");
  }
}
github agershun / olap / src / xmla.js View on Github external
function POST(path,body,async,cb){
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
      if (xhr.readyState === XMLHttpRequest.DONE) {
          if (xhr.status === 200) {
              if (cb){
                  cb(undefined,xhr.responseText);
              }
          } else if (error){
              cb(xhr);
          }
          // Todo: else...?            
      }
  };
  xhr.open("POST", path, async); // Async
  xhr.setRequestHeader("Accept", "text/xml, application/xml, application/soap+xml");
  xhr.setRequestHeader("Content-Type", "text/xml");
  xhr.send(body);
github agershun / olap / stuff / olap / xmla.js View on Github external
function POST(path,body,async,cb){
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
      if (xhr.readyState === XMLHttpRequest.DONE) {
          if (xhr.status === 200) {
              if (cb){
                  cb(undefined,xhr.responseText);
              }
          } else if (error){
              cb(xhr);
          }
          // Todo: else...?            
      }
  };
  xhr.open("POST", path, async); // Async
  xhr.setRequestHeader("Accept", "text/xml, application/xml, application/soap+xml");
  xhr.setRequestHeader("Content-Type", "text/xml");
  xhr.send(body);
github aadsm / jsmediatags / dist / jsmediatags.js View on Github external
value: function _createXHRObject() {
      if (typeof window === "undefined" && !this._isWebWorker()) {
        // $FlowIssue - flow is not able to recognize this module.
        return new (require("xhr2").XMLHttpRequest)();
      }

      if (typeof XMLHttpRequest !== "undefined") {
        return new XMLHttpRequest();
      }

      throw new Error("XMLHttpRequest is not supported");
    }
  }], [{
github asadsahi / AspNetCoreSpa / src / AspNetCoreSpa.Web / ClientApp / src / main.server.ts View on Github external
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModule, renderModuleFactory } from '@angular/platform-server';
import { APP_BASE_HREF } from '@angular/common';
import { enableProdMode } from '@angular/core';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import { createServerRenderer } from 'aspnet-prerendering';
export { AppServerModule } from './app/app.server.module';
import { COOKIES } from '@app/models';

// This allows to set cookies on server
// Only cookie used in this app is culture cookie
import * as xhr2 from 'xhr2';
xhr2.prototype._restrictedHeaders = {};

enableProdMode();

export default createServerRenderer(params => {
    const { AppServerModule, AppServerModuleNgFactory, LAZY_MODULE_MAP } = (module as any).exports;
    const options = {
        document: params.data.originalHtml,
        url: params.url,
        extraProviders: [
            provideModuleMap(LAZY_MODULE_MAP),
            { provide: APP_BASE_HREF, useValue: params.baseUrl },
            { provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
            { provide: COOKIES, useValue: params.data.cookies }
        ]
    };
github agershun / olap / src / xmla.js View on Github external
xhr.onreadystatechange = function() {
      if (xhr.readyState === XMLHttpRequest.DONE) {
          if (xhr.status === 200) {
              if (cb){
                  cb(undefined,xhr.responseText);
              }
          } else if (error){
              cb(xhr);
          }
          // Todo: else...?            
      }
  };
  xhr.open("POST", path, async); // Async
github agershun / olap / stuff / olap / xmla.js View on Github external
xhr.onreadystatechange = function() {
      if (xhr.readyState === XMLHttpRequest.DONE) {
          if (xhr.status === 200) {
              if (cb){
                  cb(undefined,xhr.responseText);
              }
          } else if (error){
              cb(xhr);
          }
          // Todo: else...?            
      }
  };
  xhr.open("POST", path, async); // Async
github angular / angular / packages / platform-server / src / http.ts View on Github external
  build(): XMLHttpRequest { return new xhr2.XMLHttpRequest(); }
}

xhr2

XMLHttpRequest emulation for node.js

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis