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

Stream headers for maxage #172

Closed
wants to merge 3 commits 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
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test

on:
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm install
- run: npm run test

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ node_modules/
.idea
lambda.zip
.aws-sam/
test-filesize
.DS_Store
dist/
/tests/test-filesize/output/
24 changes: 21 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# Contributing

## Building
## Building for Lambda

You'll need to [install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) as AWS SAM is used to build the ZIP and text the fixtures.
You'll need to [install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) as AWS SAM.

```
npm install
npm run build // Builds the function for use in SAM
npm run test // Invoke a function via SAM using a fixture from ./events/
```

### Building locally

Tachyon is written in TypeScript. All TypeScript files are in `.src` and running `npx tsc` will build everything to `./dist`. You can run `npx tsc -w` to watch for file changes to update `./dist`. This is needed if you are running the server locally (see below) or running the Lambda environment via the SAM cli (see below.)

### Running a server locally

Invoking the function via Lambda locally is somewhat slow (see below), in many cases you may want to start a local Node server which maps the Node request into a Lambda-like request. `./src/server.ts` exists for that reason. The local server will still connect to the S3 bucket (set with the `S3_BUCKET` env var) for files.


### Running Lambda Locally

Before testing any of the Lambda function calls via the `sam` CLI, you must run `sam build -u` to build the NPM deps via the Lambda docker container. This will also build the `./dist/` into the SAM environment, so any subsequent changes to files in `./src` but be first built (which updates `./dist`), and then `sam build -u` must be run.

To run Tachyon in a Lambda local environment via docker, use the `sam local invoke -e events/animated-gif.json` CLI command. This will call the function via the `src/lambda-handler.handler` function.

### Writing tests

Tests should be written using Jest. Files matching `./tests/**/test-*.ts` will automatically be included in the Jest testsuite. For tests, you don't need to run `npx tsc` to compile TypeScript files to `./dist`, as this is integrated automatically via the `ts-jest` package.

Run `npm test` to run the tests.
16 changes: 14 additions & 2 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
declare type ResponseStream = {
setContentType( type: string ): void;
write( stream: string | Buffer ): void;
end(): void;
};

declare type StreamifyHandler = ( event: APIGatewayProxyEventV2, response: ResponseStream ) => Promise<any>;

declare var awslambda: {
streamifyResponse: (
handler: ( event: APIGatewayProxyEventV2, response: ResponseStream ) => Promise<any>
) => ( event: APIGatewayProxyEventV2, context: ResponseStream ) => void;
handler: StreamifyHandler
) => ( event: APIGatewayProxyEventV2, context: ResponseStream ) => void,
HttpResponseStream: {
from: ( responseStream: ResponseStream, metadata: { statusCode: number, headers: HeadersInit } ) => ResponseStream,
},
};

16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/**/test-*.ts'],
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: './tsconfig.test.json',
},
],
},
};
Loading