當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript restify.CORS函數代碼示例

本文整理匯總了TypeScript中restify.CORS函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript CORS函數的具體用法?TypeScript CORS怎麽用?TypeScript CORS使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CORS函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ShadowsocksManagerService

      stats).then((managedAccessKeyRepository) => {
    const managerService = new ShadowsocksManagerService(managedAccessKeyRepository);
    const certificateFilename = process.env.SB_CERTIFICATE_FILE;
    const privateKeyFilename = process.env.SB_PRIVATE_KEY_FILE;

    // TODO(bemasc): Remove casts once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15229 lands
    const apiServer = restify.createServer({
      certificate: fs.readFileSync(certificateFilename),
      key: fs.readFileSync(privateKeyFilename)
    });

    // Pre-routing handlers
    apiServer.pre(restify.CORS());

    // All routes handlers
    const apiPrefix = process.env.SB_API_PREFIX ? `/${process.env.SB_API_PREFIX}` : '';
    apiServer.pre(restify.pre.sanitizePath());
    apiServer.use(restify.jsonp());
    apiServer.use(restify.bodyParser());
    setApiHandlers(apiServer, apiPrefix, managerService, stats, serverConfig);

    // TODO(fortuna): Bind to localhost or unix socket to avoid external access.
    apiServer.listen(portNumber, () => {
      logging.info(`Manager listening at ${apiServer.url}${apiPrefix}`);
    });
  });
開發者ID:fang2x,項目名稱:outline-server,代碼行數:26,代碼來源:main.ts

示例2: bootstrap

  public bootstrap(port: number) {
    this.restifyApplication.use(restify.CORS());
    this.restifyApplication.use(restify.pre.sanitizePath());
    this.restifyApplication.use(restify.acceptParser(this.restifyApplication.acceptable));
    this.restifyApplication.use(restify.bodyParser());
    this.restifyApplication.use(restify.queryParser());
    this.restifyApplication.use(restify.authorizationParser());
    this.restifyApplication.use(restify.fullResponse());

    // configure API and error routes
    this.restifyContactRouter.configApiRoutes(this.restifyApplication);
    this.restifyContactRouter.configErrorRoutes(this.restifyApplication);
    // listen on provided ports
    this.restifyApplication.listen(port, () => {
      console.log("%s listening at %s", this.restifyApplication.name, this.restifyApplication.url);
    });
  }
開發者ID:rajajhansi,項目名稱:aspnetcore-aurelia-tutorial,代碼行數:17,代碼來源:restify-application.ts

示例3: enableCORSFix

  /**
   * a crude CORS based on `Qwerios`' comment in
   * https://github.com/mcavage/node-restify/issues/664
   *
   * See issues:
   * https://github.com/mcavage/node-restify/issues/284 (closed)
   * https://github.com/mcavage/node-restify/issues/664 (unresolved)
   *
   * @param additionalHeaders string[]
   * @return void
   */
  enableCORSFix(additionalHeaders: string[] = []): void {
    /*************************************
     Cors
     **************************************/
    this.server.use(restify.CORS());
    let headers = [
      "authorization",
      "withcredentials",
      "x-requested-with",
      "x-forwarded-for",
      "x-real-ip",
      "user-agent",
      "keep-alive",
      "host",
      "accept",
      "connection",
      "upgrade",
      "content-type",
      "dnt",
      "if-modified-since",
      "cache-control"
    ];

    restify.CORS.ALLOW_HEADERS = [
      ...restify.CORS.ALLOW_HEADERS || [],
      ...headers,
      ...additionalHeaders || []
    ];

    // Manually implement the method not allowed handler to fix failing
    // preflights
    this.server.on(
      "MethodNotAllowed",
      (request: Request, response: Response) => {
        if (request.method.toUpperCase() !== "OPTIONS") {
          response.send(new restify.MethodNotAllowedError());
          return;
        } else {
          // Send the CORS headers
          //
          response.header("Access-Control-Allow-Credentials", true);
          response.header(
            "Access-Control-Allow-Headers",
            restify.CORS.ALLOW_HEADERS.join(", ")
          );
          response.header(
            "Access-Control-Allow-Methods",
            "GET, HEAD, POST, PUT, DELETE, OPTIONS"
          );
          response.header(
            "Access-Control-Allow-Origin",
            request.headers.origin
          );
          response.header("Access-Control-Max-Age", 0);
          response.header("Content-type", "text/plain charset=UTF-8");
          response.header("Content-length", 0);

          response.send(204);
        }
      }
    );
  }
開發者ID:SonicRainBoom,項目名稱:lib_router,代碼行數:73,代碼來源:router.ts

示例4: require

import * as restify from 'restify';
import * as fs from 'fs';
import {settings} from './config';
import {logger} from './logger';
import * as auth from './core/auth';

var server = restify.createServer({
    name: settings.name,
    log: logger
});

restify.CORS.ALLOW_HEADERS.push('authorization');
server.use(restify.CORS());
server.pre(restify.pre.sanitizePath());
server.use(restify.acceptParser(server.acceptable));
server.use(restify.bodyParser());
server.use(restify.queryParser());
server.use(restify.authorizationParser());
server.use(restify.fullResponse());
server.use(auth.Auth());

fs.readdirSync(__dirname + '/routes').forEach(function (routeConfig:string) {
    if (routeConfig.substr(-3) === '.js') {
        var route = require(__dirname + '/routes/' + routeConfig);
        route.routes(server);
    }
});

server.listen(settings.port, function () {
    console.log(`INFO: ${settings.name} is running at ${server.url}`);
});
開發者ID:giautm,項目名稱:zeroth,代碼行數:31,代碼來源:app.ts

示例5:

server.address().family;
server.address().address;

server.listen("somePath", send);
server.close();

server.use(restify.acceptParser(server.acceptable));
server.use(restify.authorizationParser());
server.use(restify.dateParser());
server.use(restify.queryParser());
server.use(restify.jsonp());
server.use(restify.gzipResponse());
server.use(restify.bodyParser());
server.use(restify.CORS({
    origins: ['https://foo.com', 'http://bar.com', 'http://baz.com:8081'],
    credentials: true,
    headers: ['x-foo']
}));
server.use(restify.throttle({
    burst: 100,
    rate: 50,
    ip: true,
    overrides: {
        '192.168.1.1': {
            rate: 0,
            burst: 0
        }
    }
}));

server.on('after', restify.auditLogger({
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:restify-tests.ts

示例6: BookStoreController

import { RedirectController } from './src/redirect-controller';

let port = 3000;
let bsController = new BookStoreController(new BookStore());
let serverController = new ServerController();
let redirectController = new RedirectController();

var server = createServer({
  formatters: {
    'application/json': function (req, res, body, cb) {
      return cb(null, saveStringify(body));
    }
  }
});
server.use(bodyParser());
server.use(CORS({}));
server.use(queryParser());


server.get('/swagger.json', serverController.getFixedSwaggerJson.bind(serverController));

// serve redirects
server.get(/^\/(a\/|avatar\/)/, redirectController.avatarRedirect.bind(redirectController));
server.get(/^\/(app|bm|it|ngh|start|two|cover|quotes|b\/|x\/)/, redirectController.redirect.bind(redirectController));

// serve public folder
server.get(/^(?!\/(book|info)).*/, serveStatic({
  directory: __dirname + '/public/',
  default: 'index.html'
}));
開發者ID:Angular2Buch,項目名稱:book-monkey2-api,代碼行數:30,代碼來源:server.ts


注:本文中的restify.CORS函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。