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

Feat/ignore csp 1 #10

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
23 changes: 0 additions & 23 deletions .circleci/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.18
lts/hydrogen
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
# Renderer-to-Image Service

An API endpoint for users to obtain an image screenshot of their OpenAttestation document.
> **Note**: This service is still in its experimental phase.

## Prerequisites

At a glance, only the following versions are supported:

- chrome-aws-lambda: v5.5.0
- Node: v12 and v14 (Lambda runtime and development respectively)

### chrome-aws-lambda - v5.5.0

Due to the [deployment package size limit of AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html), deployed functions on Netlify needs to be <= 50MB. To get around this limitation, the `chrome-aws-lambda` dependency in [package.json](./package.json) has been pinned to v5.5.0 as it is [smaller in size](https://github.com/alixaxel/chrome-aws-lambda/issues/200#issuecomment-899603464).
An API endpoint for users to obtain an image or PDF screenshot of their OpenAttestation document.

### Develop/Build - Node v14
## Prerequisites

When developing or building the Next app, please use Node v14.
- Node - v18 (`lts/hydrogen`)
- puppeteer-core - v21.3.8
- @sparticuz/chromium - v117.0.0

> Note: Node v16 does not work with the OpenAttestation library (@govtechsg/decentralized-renderer-react-components) due to an odd bug happening when the `npm run build` command is run.
### Versions must be matched correctly

### Deployed Lambda runtime for API functions - Node v12
Puppeteer ships with a preferred version of chromium. Refer to [installation instructions](https://github.com/Sparticuz/chromium#install) on how to match versions between both `puppeteer-core` and `@sparticuz/chromium`.

When deploying the API functions to Netlify, please set runtime to Node v12 by setting the following environment variable in Netlify:
### Why these dependencies

```text
AWS_LAMBDA_JS_RUNTIME=nodejs12.x
```

> Note: Node v12 is required because `chrome-aws-lambda` (Chromium) requires a shared library `libnss3.so` that seems to be missing in Node v14.
Due to the [deployment package size limit of AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html), deployed functions needs to be <= 50MB. To get around this limitation, lightweight dependencies such as `puppeteer-core` and `@sparticuz/chromium` are used.

## Getting Started

> **Note**: The deployed Netlify instance has a hard timeout at 10 seconds which is too little time for some renderers. As such, screenshoting of some OA documents may not work.

Try it out here: <https://renderer-to-image.netlify.app>

### Developing locally
Expand Down Expand Up @@ -80,5 +71,5 @@ Decoded resource after **`&anchor=`**:
**Final URL**:

```text
https://renderer-to-image.netlify.app/api/v1/render-image?q=%7B%22payload%22%3A%7B%22uri%22%3A%22https%3A%2F%2Fgallery.openattestation.com%2Fstatic%2Fdocuments%2Ftranscript-encrypted.opencert%22%7D%7D&anchor=%7B%22key%22%3A%225b433c297f3b35690461b9ee08d77f3e8ee47ec86e5b8b1322b056da6f0b86c4%22%7D
https://renderer-to-image.netlify.app/api/v1/render-image?q=%7B%22payload%22%3A%7B%22uri%22%3A%22https%3A%2F%2Fgallery.openattestation.com%2Fstatic%2Fdocuments%2Ftranscript-encrypted.opencert%22%7D%7D&anchor=%7B%22key%22%3A%22691add1930798b63b17c8683a4776bedc16771ea5664337e21a563be0529024f%22%7D
```
9 changes: 1 addition & 8 deletions fixtures/online-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ export const sampleCerts: {
{
title: "[Encrypted] OpenCerts Demo",
q: { payload: { uri: "https://gallery.openattestation.com/static/documents/transcript-encrypted.opencert" } },
anchor: { key: "5b433c297f3b35690461b9ee08d77f3e8ee47ec86e5b8b1322b056da6f0b86c4" },
anchor: { key: "691add1930798b63b17c8683a4776bedc16771ea5664337e21a563be0529024f" },
},
{
title: "[Plaintext] PDT HealthCert v2.0",
q: { payload: { uri: "https://schemata.openattestation.com/sg/gov/moh/pdt-healthcert/2.0/endorsed-wrapped.json" } },
},
{
title: "[Encrypted] PDT HealthCert v2.0",
q: {
payload: { uri: "https://api-vaccine.storage.staging.notarise.io/document/44409930-70b6-4ab7-94be-86cf57c9ed87" },
},
anchor: { key: "52ae6dafd2ce6f818ccb7d893f4fb58416453f42c4624a9c6a98abf0760f2119" },
},
];
Loading