diff --git a/backend/src/controllers/Remote.php b/backend/src/controllers/Remote.php index d022ad6..ea8a35f 100644 --- a/backend/src/controllers/Remote.php +++ b/backend/src/controllers/Remote.php @@ -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); + } } diff --git a/backend/src/public/index.php b/backend/src/public/index.php index d310c37..c3f617d 100644 --- a/backend/src/public/index.php +++ b/backend/src/public/index.php @@ -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 () { diff --git a/backend/test/tests/remote-servertime.js b/backend/test/tests/remote-servertime.js new file mode 100644 index 0000000..8066bd3 --- /dev/null +++ b/backend/test/tests/remote-servertime.js @@ -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!'); + }); +}); \ No newline at end of file