<?php
/*
* @var \Laravel\Lumen\Routing\Router $router
*/

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$router->get('/', function () use ($router) {
    return $router->app->version();
});
$router->group(['prefix' => 'api'], function () use ($router) {
    $router->get('/applications', 'ApplicationController@index');
    $router->group(['middleware' => 'appToken'], function () use ($router) {
        $router->post('/events', 'AnalyticsEventController@storeEvent');
    });
});

$router->get('/js/ya.js', function () use ($router) {
    $view = view('jscode', [
        'url' => env('APP_URL')
    ]);
    $headers = [
        "Content-type" => "application/javascript",
        "Cache-Control" => "max-age=604800"
    ];
    return response($view, 200, $headers);
});
