cross domain request


Cross-domain request

If a route or group needs to support cross-domain requests, you can use

Route::get('new/:id', 'News/read')
    ->ext('html')
    ->allowCrossDomain();

Cross-domain requests will generally Send an OPTIONS request. Once a cross-domain request is set up, you do not need to define the route for the OPTIONS request yourself, the system will automatically add it.

The cross-domain request system will bring some headers by default, including:

Access-Control-Allow-Origin:*
Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE
Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With

You can add or change Header information using

Route::get('new/:id', 'News/read')
    ->ext('html')
    ->allowCrossDomain([
        'Access-Control-Allow-Origin'        => 'thinkphp.cn',
        'Access-Control-Allow-Credentials'   => 'true'
    ]);