# Add CORS to a Quarkus REST API

Yes. An agent enables Quarkus's built-in CORS filter for a named origin list in application.properties, adds RestAssured preflight tests, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-cors/quarkus/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the project as it is. In a service shaped like `hibernate-orm-panache-quickstart` in quarkusio/quarkus-quickstarts it opens `pom.xml` and finds the Quarkus platform at 3.40.1.1 with `quarkus-hibernate-orm-panache`, `quarkus-rest-jackson`, `quarkus-jdbc-postgresql`, `quarkus-junit` and `rest-assured`, and a Maven wrapper so `./mvnw` needs no local install. It reads `src/main/resources/application.properties`, which sets `quarkus.hibernate-orm.log.sql=true`, loads `import.sql` and configures the `%prod` datasource, and nothing under `quarkus.http`. It reads the two resources, `FruitEntityResource` at `entity/fruits` and `FruitRepositoryResource` at `repository/fruits`, each with GET, GET by id, POST, PUT and DELETE, and the AngularJS page under `META-INF/resources/index.html` that calls `/entity/fruits` from the same origin, which is why nothing has needed CORS so far.

Quarkus ships a CORS filter in its HTTP layer, so the change is configuration, not code. The agent adds `quarkus.http.cors.enabled=true` and a `quarkus.http.cors.origins` list to `application.properties`, with the methods the resources actually expose, `GET,POST,PUT,DELETE,OPTIONS`, in `quarkus.http.cors.methods`, `Content-Type` and `Accept` in `quarkus.http.cors.headers`, and an `access-control-max-age` so browsers cache the preflight. It does not use a wildcard origin: the prompt names the front-end origin, and the agent writes that one into the `%prod` profile and a `http://localhost:5173`-style development origin into `%dev`, so the two never share a line. A `%test` entry sets a known origin the tests can send.

Then it writes the tests where the project already has them. `FruitsEndpointTest` is a `@QuarkusTest` that runs `performTest` against both resource paths with RestAssured, and `FruitsEndpointIT` extends it under `@QuarkusIntegrationTest` so the same cases run against the packaged application. The agent adds a `CorsTest` beside them: an OPTIONS request to `/entity/fruits` with `Origin` set to the test origin and `Access-Control-Request-Method: POST` must answer with `Access-Control-Allow-Origin` equal to that origin and `Access-Control-Allow-Methods` containing POST; the same request from an origin not on the list must come back without the allow header; and a plain GET with the allowed `Origin` must carry the header on the real response, not only the preflight.

It runs `./mvnw test`, which starts the Postgres Dev Service the README describes, in the sandbox's Docker, and then `./mvnw verify` so the integration test class runs too. If a property name does not match the platform version in the pom, the build log says so and the agent fixes it before pushing. Then it opens a pull request with the three properties blocks and the test class in the diff.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add CORS to this Quarkus REST API so a browser front end at https://app.example.com can call /entity/fruits and /repository/fruits. Use Quarkus's built-in quarkus.http.cors configuration in application.properties with that origin in the prod profile, a localhost origin in the dev profile and a fixed origin in the test profile, never a wildcard. Allow GET, POST, PUT, DELETE and OPTIONS and the Content-Type and Accept headers. Add a RestAssured test class covering a successful preflight, a rejected origin and the header on a real GET, run ./mvnw verify, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch. The diff adds a `quarkus.http.cors` block to `src/main/resources/application.properties`, with the origin split across the `%prod`, `%dev` and `%test` profiles, and a new `CorsTest` under `src/test/java/org/acme/hibernate/orm/panache` beside the existing endpoint tests. No Java source under `src/main` changes, because the filter is part of Quarkus's HTTP layer and the resources do not need to know about it. The description lists the allowed origins, methods and headers so a reviewer can compare them to what the front end sends.

The repository's own build is the check. The `build-pr-development.yml` workflow builds the quickstarts on JDK 21 for every pull request, so the new test class runs there against a Dev Services Postgres, the same way it runs in the sandbox. The session's trajectory at `GET /o/{org}/sessions/{id}/messages` keeps every `./mvnw test` and `./mvnw verify` invocation with its Surefire and Failsafe output.

Before merging, a reviewer checks three things: that the `%prod` origin is the real front end and not the placeholder from the prompt, that no profile contains `*`, and that `OPTIONS` is in the method list, since a browser's preflight fails without it even when the real method is allowed. The sandbox pushes one branch and nothing else.

## Run it on every new front end for a service

A team that stands up a separate browser front end for each Quarkus service starts one run per repository with `POST /o/{org}/sessions`, this prompt with that front end's origin in it, and the repository in `resources`. Each run reads its own `application.properties` and its own resources, so a service that already has a `quarkus.http.cors` block gets the new origin added to the list rather than a duplicate block, and each opens its own pull request.

Set a `webhook_url` on the API key and every run the key starts posts `run.completed` or `run.failed` when it finishes, with a `session_url` for the result. The key runs at most `max_concurrent` sessions at once, 4 by default, and a fleet of services can be sent all at once: the sessions beyond that are created with `202` and `status: "queued"`, then start, oldest first, as slots free.

## Why run it on Rush?

CORS is a five-line change and a day of confusion when it is wrong, because the browser reports almost nothing and the preflight never reaches the resource. Proving it means a running Quarkus with a database behind it, which in this project is a Docker Postgres that Dev Services starts for you, and a `./mvnw verify` that packages the app for the integration test. On Rush the run has its own sandbox with a computer in it: the agent runs the Maven wrapper against the sandbox's Docker as often as it needs, and your own machine runs nothing.

The result is checkable rather than claimed. The pull request shows the exact origins, methods and headers, the CI workflow the repository already has runs the new test class on JDK 21, and the trajectory keeps every build with its output, so a reviewer can read the preflight assertion passing before trusting the properties. Several services mean several sandboxes and several pull requests at once.

## Frequently asked questions

### Does this add a dependency?

No. The CORS filter is part of Quarkus's HTTP layer, which `quarkus-rest-jackson` already brings in, so `pom.xml` is untouched. The whole change is properties and a test class.

### Why not just allow every origin?

Because a wildcard with credentials is refused by browsers and without credentials it lets any site call the API. The prompt names the origin, the agent writes it into the `%prod` profile, and the test for a rejected origin fails if someone later replaces the list with `*`.

### How do the tests run without a Postgres of my own?

The quickstart's README explains that Dev Services starts a Postgres container for dev and test modes when no datasource URL is configured for that profile, and `application.properties` only sets one under `%prod`. The sandbox has Docker, so `./mvnw test` starts the database the same way it does on a developer machine and in the repository's CI.

### Will the existing index.html page still work?

Yes. It is served from `META-INF/resources` on the same origin as the API, so it never sends a cross-origin request and the filter does not apply to it. The existing `FruitsEndpointTest` cases run unchanged and keep proving the resources themselves.

### What if my front end sends an Authorization header?

Say so in the prompt and the agent adds `Authorization` to `quarkus.http.cors.headers` and, if cookies are involved, `quarkus.http.cors.access-control-allow-credentials=true`, with a test that the preflight lists the header. The defaults in this page cover a JSON client that sends `Content-Type` and `Accept` only.

## More Quarkus jobs

- [Add Test Coverage Reporting to Quarkus CI](https://getrush.ai/run/add-coverage-to-ci/quarkus/)
- [Add CSV Export to a Quarkus REST API](https://getrush.ai/run/add-csv-export/quarkus/)
- [Add Cursor Pagination to a Quarkus Panache REST Endpoint](https://getrush.ai/run/add-cursor-pagination/quarkus/)

## The same job on other stacks

- [Add CORS to a Rocket JSON API](https://getrush.ai/run/add-cors/rocket/)
- [Add CORS to a Serverless Framework API from a Linear Issue](https://getrush.ai/run/add-cors/serverless/)
- [Add CORS to a Slim 4 API](https://getrush.ai/run/add-cors/slim/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
