当前位置: 首页>>代码示例>>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;未经允许,请勿转载。