require "views/app.html";
    die;
});
$app->get('/logout', function () use($helper) {
    $helper->destroyToken();
    header("Location: /");
    die;
});
$app->get('/oauth2callback', function () use($helper) {
    $helper->callBackLogic();
    die;
});
// GET TASKS
$app->get('/tasks-json', function () use($service, $helper) {
    //    sleep(2);
    $data = $service->getListsArray(true);
    return new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));
});
$app->get('/tasks-json/{listId}', function ($listId) use($service) {
    if ($service instanceof GtaskHelperCached) {
        $service->resetListCache($listId);
    }
    $data = $service->getTasksInListArray($listId);
    return new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));
});
// ADD TASK
$app->post('/list/{listId}/tasks', function (Request $request, $listId) use($service) {
    $task = json_decode($request->getContent());
    $addedTask = $service->addTask($listId, $task->title);
    /* @var $task \Google_Service_Tasks_Task */
    return new Response(json_encode(GtaskHelper::taskToArray($addedTask)), 200, array('Content-Type' => 'application/json'));