Skip to content

http OPTIONS request returns full result with data in body #128

@judos

Description

@judos

In our application we have a jwt header which gets sent to the cms. Naturally thus the browser does a preflight request before sending the actual request and it just realized that element-api returns already a full response with data in the preflight request "OPTIONS /endpoint" as well as then in the "GET /endpoint".
Shouldn't element api only serve GET requests?
Is there a way to configure this?

The element-api.php looks like this:

return [
	'defaults' => [
		'elementType' => Entry::class,
		'resourceKey' => 'elements',
		'pretty' => Craft::$app->getConfig()->general->devMode,
		'paginate' => false,
		'cache' => ApiHelper::enableCache(300),
	],
	'endpoints' => [
		'pages/<slug:{slug}>' => function($slug) {
			return [
				'one' => true,
				'criteria' => [
					'section' => 'pages',
					'slug' => $slug,
				],
				'transformer' => new PageTransformer()
			];
		},
	}
]

The header that is added in angular is just this:

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    if (this.jwt) {
      req = req.clone({
        headers: req.headers.set('Authorization', 'Bearer ' + this.jwt)
      });
    }
    return next.handle(req);
  }

I didn't find anything in the documentation.

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions