Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - adding /ping for eik-client ping command #493

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ const EikService = class EikService {
// Routes
//

const pingRoute = async (request, reply) => {
reply.type('text/plain')
reply.code(200)
reply.send('pong')
}
const authPostRoutes = async (request, reply) => {
const outgoing = await this._authPost.handler(
request.raw,
Expand Down Expand Up @@ -302,7 +307,6 @@ const EikService = class EikService {
reply.redirect(outgoing.location);
};


const aliasGetRoute = async (request, reply) => {
const params = utils.sanitizeParameters(request.raw.url);
const outgoing = await this._aliasGet.handler(
Expand Down Expand Up @@ -363,6 +367,7 @@ const EikService = class EikService {
reply.send(outgoing.body);
};

app.get('/ping', pingRoute);

//
// Authentication
Expand All @@ -372,7 +377,6 @@ const EikService = class EikService {

app.post(`/${eik.prop.base_auth}/login`, authPostRoutes);


//
// Packages
//
Expand Down
25 changes: 25 additions & 0 deletions test/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Fastify from 'fastify';
import tap from 'tap';
import fetch from 'node-fetch'

import Sink from "@eik/core/lib/sinks/test.js";
import Server from '../lib/main.js';

tap.test('ping - returns pong', async t => {
const service = new Server({ customSink: new Sink() });

const app = Fastify({
ignoreTrailingSlash: true,
});
app.register(service.api());

const address = await app.listen({ port: 0, host: '127.0.0.1' });
const response = await fetch(`${address}/ping`, {
method: 'GET',
});
t.ok(response.ok)
t.equal(response.status, 200, 'returns 200 OK')
t.equal(await response.text(), 'pong')

await app.close()
})