Added GET /remote/servertime API

This commit is contained in:
Lukas Metzger 2018-04-29 15:08:23 +02:00
parent 799ce1b371
commit 5838f61db6
3 changed files with 23 additions and 0 deletions

View File

@ -53,4 +53,11 @@ class Remote
$this->logger->info('Record ' . $record . ' was changed via the changepw api.');
return $res->withStatus(204);
}
public function servertime(Request $req, Response $res, array $args)
{
return $res->withJson([
'time' => time()
], 200);
}
}

View File

@ -31,6 +31,7 @@ $app->group('/v1', function () {
$this->post('/sessions', '\Controllers\Sessions:post');
$this->get('/remote/ip', '\Controllers\Remote:ip');
$this->get('/remote/servertime', '\Controllers\Remote:servertime');
$this->get('/remote/updatepw', '\Controllers\Remote:updatePassword');
$this->group('', function () {

View File

@ -0,0 +1,15 @@
const test = require('../testlib');
test.run(async function () {
await test('admin', async function (assert, req) {
var res = await req({
url: '/remote/servertime',
method: 'get'
});
const curTime = Math.floor(new Date() / 1000);
assert.equal(res.status, 200);
assert.true(Math.abs(curTime - res.data.time) < 2, 'Returned time is not within tolerance!');
});
});