io.vertx.reactivex.ext.web.handler.CorsHandler Java Examples
The following examples show how to use
io.vertx.reactivex.ext.web.handler.CorsHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestfulApiVerticle.java From vertx-blueprint-todo-backend with Apache License 2.0 | 6 votes |
/** * Enable CORS support for web router. * * @param router router instance */ protected void enableCorsSupport(Router router) { Set<String> allowHeaders = new HashSet<>(); allowHeaders.add("x-requested-with"); allowHeaders.add("Access-Control-Allow-Origin"); allowHeaders.add("origin"); allowHeaders.add("Content-Type"); allowHeaders.add("accept"); // CORS support router.route().handler(CorsHandler.create("*") .allowedHeaders(allowHeaders) .allowedMethod(HttpMethod.GET) .allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.DELETE) .allowedMethod(HttpMethod.PATCH) .allowedMethod(HttpMethod.PUT) ); }
Example #2
Source File: CorsHandlerFactory.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Override public CorsHandler getObject() { return CorsHandler.newInstance(io.vertx.ext.web.handler.CorsHandler .create(environment.getProperty("http.cors.allow-origin", String.class, "*")) .allowedHeaders(getStringPropertiesAsList("http.cors.allow-headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With, If-Match, x-xsrf-token")) .allowedMethods(getHttpMethodPropertiesAsList("http.cors.allow-methods", "GET, POST")) .maxAgeSeconds(environment.getProperty("http.cors.max-age", Integer.class, 86400))); }
Example #3
Source File: PublicApiVerticle.java From vertx-in-action with MIT License | 4 votes |
@Override public Completable rxStart() { String publicKey; String privateKey; try { publicKey = CryptoHelper.publicKey(); privateKey = CryptoHelper.privateKey(); } catch (IOException e) { return Completable.error(e); } jwtAuth = JWTAuth.create(vertx, new JWTAuthOptions() .addPubSecKey(new PubSecKeyOptions() .setAlgorithm("RS256") .setBuffer(publicKey)) .addPubSecKey(new PubSecKeyOptions() .setAlgorithm("RS256") .setBuffer(privateKey))); Router router = Router.router(vertx); Set<String> allowedHeaders = new HashSet<>(); allowedHeaders.add("x-requested-with"); allowedHeaders.add("Access-Control-Allow-Origin"); allowedHeaders.add("origin"); allowedHeaders.add("Content-Type"); allowedHeaders.add("accept"); allowedHeaders.add("Authorization"); Set<HttpMethod> allowedMethods = new HashSet<>(); allowedMethods.add(HttpMethod.GET); allowedMethods.add(HttpMethod.POST); allowedMethods.add(HttpMethod.OPTIONS); allowedMethods.add(HttpMethod.PUT); router.route().handler(CorsHandler .create("*") .allowedHeaders(allowedHeaders) .allowedMethods(allowedMethods)); BodyHandler bodyHandler = BodyHandler.create(); router.post().handler(bodyHandler); router.put().handler(bodyHandler); String prefix = "/api/v1"; JWTAuthHandler jwtHandler = JWTAuthHandler.create(jwtAuth); // Account router.post(prefix + "/register").handler(this::register); router.post(prefix + "/token").handler(this::token); // Profile router.get(prefix + "/:username").handler(jwtHandler).handler(this::checkUser).handler(this::fetchUser); router.put(prefix + "/:username").handler(jwtHandler).handler(this::checkUser).handler(this::updateUser); // Data router.get(prefix + "/:username/total").handler(jwtHandler).handler(this::checkUser).handler(this::totalSteps); router.get(prefix + "/:username/:year/:month").handler(jwtHandler).handler(this::checkUser).handler(this::monthlySteps); router.get(prefix + "/:username/:year/:month/:day").handler(jwtHandler).handler(this::checkUser).handler(this::dailySteps); webClient = WebClient.create(vertx); return vertx.createHttpServer() .requestHandler(router) .rxListen(HTTP_PORT) .ignoreElement(); }
Example #4
Source File: CorsHandlerFactory.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
@Override public Class<?> getObjectType() { return CorsHandler.class; }