当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript cors.default方法代码示例

本文整理汇总了TypeScript中cors.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript cors.default方法的具体用法?TypeScript cors.default怎么用?TypeScript cors.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cors的用法示例。


在下文中一共展示了cors.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: bootstrap

  public bootstrap(port: number) {
    // enable CORS
    this.expressApplication.use(cors(), (request: express.Request, response: express.Response, next: express.NextFunction) => {
        console.log("CORS enabled for all routes");
        next();
    });

    // configure API and error routes   
    this.expressContactRouter.configApiRoutes(this.expressApplication);
    this.expressContactRouter.configErrorRoutes(this.expressApplication);
    this.expressApplication.set("port", port);

    // create http server
    let server = http.createServer(this.expressApplication);
    server.listen(port);
    // add error handler
    server.on("error", onError);

    // start listening on port
    server.on("listening", onListening);

    // event listener for HTTP server "error" event.
    function onError(error: any) {
        "use strict";
        if (error.syscall !== "listen") {
            throw error;
        }

        let bind = typeof port === "string"
        ? "Pipe " + port
        : "Port " + port;

        // handle specific listen errors with friendly messages
        switch (error.code) {
        case "EACCES":
            console.error(bind + " requires elevated privileges");
            process.exit(1);
            break;
        case "EADDRINUSE":
            console.error(bind + " is already in use");
            process.exit(1);
            break;
        default:
            throw error;
        }
    }

    /**
     * Event listener for HTTP server "listening" event.
     */
    function onListening() {
        let addr = server.address();
        let bind = typeof addr === "string"
        ? "pipe " + addr
        : "port " + addr.port;
        let debugForExpress = debug("ExpressApplication");
        debugForExpress("Listening on " + bind);
    }
  }
开发者ID:rajajhansi,项目名称:aspnetcore-aurelia-tutorial,代码行数:59,代码来源:express-application.ts

示例2: if

export let parserInit = ()=> {
    app.use(favicon(path.resolve('favicon.ico')));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));
    app.use(cookieParser());
    if (SERVER_CONFIG.env === DEV) {
        app.use(logger(DEV));
        var whitelist = ['http://127.0.0.1:3008','http://127.0.0.1:3006'];
        var corsOptionsDelegate = function(req, callback){
            var corsOptions;
            if(whitelist.indexOf(req.header('Origin')) !== -1){
                corsOptions = { origin: true ,credentials:true}; // reflect (enable) the requested origin in the CORS response
            }else{
                corsOptions = { origin: false }; // disable CORS for this request
            }
            callback(null, corsOptions); // callback expects two parameters: error and options
        };
        /*var corsOptions = {
            origin: 'http://127.0.0.1:3008',
            optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
        };*/
        app.use(cors(corsOptionsDelegate));//white List
        //app.options('http://127.0.0.1:3008', cors());//If allowed Access-Control-Allow-Origin:* Be sure to write
    }
    else if (SERVER_CONFIG.env === PROD) {
        app.use(logger('prod'));
    }
    timeoutParser.init();
    errParser.init();
    parserInit = ()=> {
        throw new Error("parsers/index.ts: parsers have been initialized.");
    }
}
开发者ID:guoyu07,项目名称:react-node-cms,代码行数:33,代码来源:parserInit.ts

示例3: main

async function main() {
  const app = express();
  app.use(cors());

  await initAccounts();

  app.use(session({
    secret: 'grant',
    resave: true,
    saveUninitialized: true,
  }));

  app.use(bodyParser.urlencoded({ extended: true }));

  const grant = new Grant(grantConfig);

  app.use(GRANT_PATH, grant);

  app.get(`${GRANT_PATH}/handle_facebook_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=facebook&access_token=${accessToken}`);
  });

  app.get(`${GRANT_PATH}/handle_google_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`);
  });

  initializeOAuthResolver();

  const schema = createSchemeWithAccounts(AccountsServer);

  app.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
    schema,
    context: JSAccountsContext(request),
    debug: true,
  })));

  app.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
  }));

  const server = createServer(app);

  new SubscriptionServer(
    {
      schema,
      execute,
      subscribe,
    },
    {
      path: WS_GQL_PATH,
      server,
    }
  );

  server.listen(PORT, () => {
    console.log('Mock server running on: ' + PORT);
  });
}
开发者ID:RocketChat,项目名称:Rocket.Chat.PWA,代码行数:60,代码来源:index.ts

示例4: callback

server.setConfig((app) => {

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());
    app.use(morgan('combined'));
    app.use(cors({
        origin: (origin, callback) => {
            try {
                let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
                callback(null, ok);
            } catch (e) {
                callback(e, null);
            }

        }
    }));
    app.use(jwt({ secret: config.appSecret })
        .unless({
            path: ['/api/account/login', '/setup', '/',
                {
                    url: '/api/donors',
                    methods: ['GET', 'POST']
                }]
        }));

   let feed: DonorsFeed = kernel.get<DonorsFeed>(TYPES.DonorsFeed);
   feed.start(httpServer);
});
开发者ID:kibiluzbad,项目名称:kamrusepa,代码行数:28,代码来源:server.ts

示例5: constructor

 constructor(options) {
     var corsOptions = {
         credentials: options.credentials || true,
         origin: options.origin || function(origin, callback) {
             callback(null, true);
         }
     };
     Container.get('app').use(cors(corsOptions));
 }
开发者ID:nicolanrizzo,项目名称:node-microframework-cors,代码行数:9,代码来源:CorsPlugin.ts

示例6: constructor

  constructor() {
    this.app = express();

    this.app.use(cors());
    this.app.use(bodyParser.json());
    this.app.use(bodyParser.urlencoded({ extended: false }));

    this.setupSwagger();
    this.setupControllers();
  }
开发者ID:efueger,项目名称:node-microservice-demo,代码行数:10,代码来源:Express.ts

示例7: constructor

    /**
     * Constructor.
     *
     * @class Server
     * @constructor
     */
    constructor() {
        // create expressjs application
        this.app = express();
        this.app.use(bodyParser.json());

        this.app.use(cors());

        // configure application
        this.config();
    }
开发者ID:fabiopavesi,项目名称:EDI-NG_client,代码行数:16,代码来源:server.ts

示例8: registerCors

 private registerCors() {
     // Cors
     var corsOptions = {
         credentials: true,
         origin: function(origin, callback) {
             callback(null, true);
         }
     };
     this.app.use(cors(corsOptions));
 }
开发者ID:nicolanrizzo,项目名称:node-microframework,代码行数:10,代码来源:application.ts

示例9: express

export const expressConfig = (): core.Express => {
  const app: core.Express = express();
  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'assets')));
  app.use(cors());
  app.use(compression({filter: shouldCompress}));

  return app;
};
开发者ID:Cyphle,项目名称:Portfolio,代码行数:11,代码来源:express.config.ts

示例10: setup

	public setup() {
		this.logger.debug("Enabling CORS");

		let corsOptions = {
			origin: "*",
			methods: ["GET", "PUT", "POST", "PATCH", "DELETE"],
			credentials: true,
			preflightContinue: true,
		};

		this.app.use(cors(corsOptions));
	}
开发者ID:Event-Starter-Kit,项目名称:website,代码行数:12,代码来源:010.cors.ts


注:本文中的cors.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。