Skip to content

Commit

Permalink
Adding /about endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed May 5, 2020
1 parent 0d014df commit 2de9194
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ functions:
method: GET
cors: true
private: true
narcissusAbout:
handler: src/about.handler
environment:
DEBUG: 0
events:
- http:
path: narcissus-${env:ENV}/about
method: GET
cors: true
private: true

package:
exclude:
Expand Down
9 changes: 9 additions & 0 deletions src/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.handler = async () => {
const body = {
'/?url=:url&selector=:selector': 'Saves a screenshot of the whole webpage related to the mandatory "url" parameter or limited by the element represented by the optional "selector" parameter, which is supported to be a CSS selector. Returns an object with a "url" key pointing to the public address of the screenshot, or an "error" key with an error message.',
};
return {
statusCode: 200,
body: JSON.stringify(body),
};
};
15 changes: 14 additions & 1 deletion src/local.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const lambda = require('./index').handler;
const about = require('./about').handler;

const app = express();
const port = process.env.SERVER_PORT || 8687;
Expand All @@ -11,9 +12,21 @@ const handleError = (e, response) => {
response.status(500).send(JSON.stringify({ error: 'Error 500, please check the logs' }));
};

const invalidRequest = (request) => (request.headers['x-api-key'] !== 'dev');

app.get('/about', (request, response) => {
if (invalidRequest(request)) {
response.status(403).send('Please provide the API key');
} else {
about().then((aboutResponse) => {
response.status(aboutResponse.statusCode).send(aboutResponse.body);
});
}
});

app.get('/', (request, response) => {
try {
if (request.headers['x-api-key'] !== 'dev') {
if (invalidRequest(request)) {
response.status(403).send('Please provide the API key');
} else {
const requestRef = request;
Expand Down
6 changes: 6 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let puppeteer = require('puppeteer-core');
const index = require('./index');
const config = require('./config');
const getChromeFromLocal = require('./getChromeFromLocal');
const about = require('./about');

jest.setTimeout(120000);

Expand Down Expand Up @@ -83,3 +84,8 @@ test('should use default callback', async () => {
const response = await index.handler(e, { runningLocally: false }, callback);
expect(response.statusCode).toBe(200);
});

test('should information about the service', async () => {
const response = await about.handler();
expect(response.statusCode).toBe(200);
});

0 comments on commit 2de9194

Please sign in to comment.