Skip to content

Commit f4f12a1

Browse files
committed
prettier
1 parent 9eebbe8 commit f4f12a1

33 files changed

+4810
-4118
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node: [ '14', '16', '18' ]
12+
node: ["14", "16", "18"]
1313
name: Node ${{ matrix.node }}
1414

1515
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-node@v3
18-
with:
19-
node-version: ${{ matrix.node }}
20-
- run: npm install
21-
- run: npm test
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ matrix.node }}
20+
- run: npm install
21+
- run: npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules
22
*tgz
33
/dist
44
coverage
5+
public
6+
views
7+

.prettierignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
static
2+
node_modules
3+
coverage
4+
__sapper__
5+
src/parser
6+
.vscode
7+
package-lock.json
8+
.svelte-kit
9+
build
10+
dist
11+

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"bracketSameLine": true
4+
}

.vscode/css-custom-data.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"version": 1.1,
3+
"atDirectives": [
4+
{
5+
"name": "@tailwind",
6+
"description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.",
7+
"references": [
8+
{
9+
"name": "Tailwind Documentation",
10+
"url": "https://tailwindcss.com/docs/functions-and-directives#tailwind"
11+
}
12+
]
13+
},
14+
{
15+
"name": "@responsive",
16+
"description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n .alert {\n background-color: #E53E3E;\n }\n}\n```\n",
17+
"references": [
18+
{
19+
"name": "Tailwind Documentation",
20+
"url": "https://tailwindcss.com/docs/functions-and-directives#responsive"
21+
}
22+
]
23+
},
24+
{
25+
"name": "@screen",
26+
"description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n /* ... */\n}\n```\n",
27+
"references": [
28+
{
29+
"name": "Tailwind Documentation",
30+
"url": "https://tailwindcss.com/docs/functions-and-directives#screen"
31+
}
32+
]
33+
},
34+
{
35+
"name": "@variants",
36+
"description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n",
37+
"references": [
38+
{
39+
"name": "Tailwind Documentation",
40+
"url": "https://tailwindcss.com/docs/functions-and-directives#variants"
41+
}
42+
]
43+
},
44+
{
45+
"name": "@apply",
46+
"description": "Use @apply to inline any existing utility classes into your own custom CSS.",
47+
"references": [
48+
{
49+
"name": "Tailwind Documentation",
50+
"url": "https://tailwindcss.com/docs/functions-and-directives#apply"
51+
}
52+
]
53+
}
54+
]
55+
}

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "recommendations": ["svelte.svelte-vscode"] }

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-chrome",
9+
"request": "launch",
10+
"name": "Launch Chrome against localhost",
11+
"url": "http://localhost:3000",
12+
"webRoot": "${workspaceFolder}"
13+
}
14+
]
15+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"prettier.configPath": ".prettierrc",
3+
"editor.formatOnSave": true,
4+
"css.customData": [".vscode/css-custom-data.json"]
5+
}

README.md

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@ An npm module that allows your Node.js web applications to be deployed as an AWS
55
[![Build Status](https://travis-ci.org/janaz/lambda-request-handler.svg?branch=master)](https://travis-ci.org/janaz/lambda-request-handler)
66

77
The list of supported frameworks matches [in-process-request](https://github.com/janaz/in-process-request)
8-
* Express.js v3
9-
* Express.js v4
10-
* Express.js v5
11-
* Apollo Server v2
12-
* Hapi v19 (only supported in `nodejs12.x` runtime)
13-
* Hapi v20 (only supported in `nodejs12.x` runtime)
14-
* NestJS v7
15-
* Connect v3
16-
* Koa v2
17-
* Polka
18-
* Fastify v3
8+
9+
- Express.js v3
10+
- Express.js v4
11+
- Express.js v5
12+
- Apollo Server v2
13+
- Hapi v19 (only supported in `nodejs12.x` runtime)
14+
- Hapi v20 (only supported in `nodejs12.x` runtime)
15+
- NestJS v7
16+
- Connect v3
17+
- Koa v2
18+
- Polka
19+
- Fastify v3
1920

2021
Inspired by [aws-serverless-express](https://github.com/awslabs/aws-serverless-express)
2122

2223
It supports `nodejs10.x` and `nodejs12.x` execution environments.
2324

2425
The main differences between this module and `aws-serverless-express` are
25-
* It's using [in-process-request](https://github.com/janaz/in-process-request) module to execute app handlers in-process without having to start background http server
26-
* Simpler setup as it doesn't require managing the internal http server
27-
* Support for applications that require asynchronous setup (for example reading config from network, or decrypting secrets from KMS)
28-
* It's faster, because it doesn't need to pass the request to the internal server through the unix socket
29-
* It's free from issues caused by limits in Node.js http module such as header size limit
26+
27+
- It's using [in-process-request](https://github.com/janaz/in-process-request) module to execute app handlers in-process without having to start background http server
28+
- Simpler setup as it doesn't require managing the internal http server
29+
- Support for applications that require asynchronous setup (for example reading config from network, or decrypting secrets from KMS)
30+
- It's faster, because it doesn't need to pass the request to the internal server through the unix socket
31+
- It's free from issues caused by limits in Node.js http module such as header size limit
3032

3133
The handler supports events from the following sources:
34+
3235
- API Gateway [REST APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html)
3336
- API Gateway [HTTP APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html)
3437
- [Application Load Balancer](https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html)
@@ -42,13 +45,15 @@ There's a [demo app](https://github.com/janaz/lambda-request-handler-example) sh
4245
The default export of `lambda-request-handler` is a function that takes an application handler (i.e. Express.js app instance) as an argument and returns an AWS Lambda handler function.
4346

4447
An additional header is injected into the request
45-
* `x-aws-lambda-request-id` - AWS Lambda Request Id
48+
49+
- `x-aws-lambda-request-id` - AWS Lambda Request Id
4650

4751
```sh
4852
$ npm install lambda-request-handler
4953
```
5054

5155
### Express.js
56+
5257
```javascript
5358
const express = require('express')
5459
const lambdaRequestHandler = require('lambda-request-handler')
@@ -75,13 +80,13 @@ If the above file in your Lambda source was called `index.js` then the name of t
7580
Sometimes the application needs to read configuration from remote source before it can start processing requests. For example it may need to decrypt some secrets managed by KMS. For this use case a special helper `deferred` has been provided. It takes a factory function which returns a Promise that resolves to the app instance. The factory function will be called only once.
7681

7782
```javascript
78-
const lambdaRequestHandler = require('lambda-request-handler')
79-
const AWS = require('aws-sdk')
80-
const express = require('express')
83+
const lambdaRequestHandler = require("lambda-request-handler")
84+
const AWS = require("aws-sdk")
85+
const express = require("express")
8186

8287
const createApp = (secret) => {
83-
const app = express();
84-
app.get('/secret', (req, res) => {
88+
const app = express()
89+
app.get("/secret", (req, res) => {
8590
res.json({
8691
secret: secret,
8792
})
@@ -90,51 +95,52 @@ const createApp = (secret) => {
9095

9196
const myAppPromise = async () => {
9297
const kms = new AWS.KMS()
93-
const data = await kms.decrypt({
94-
CiphertextBlob: Buffer.from(process.env.ENCRYPTED_SECRET, 'base64')
95-
}).promise()
96-
const secret = data.Plaintext.toString('ascii')
97-
return createApp(secret);
98-
};
98+
const data = await kms
99+
.decrypt({
100+
CiphertextBlob: Buffer.from(process.env.ENCRYPTED_SECRET, "base64"),
101+
})
102+
.promise()
103+
const secret = data.Plaintext.toString("ascii")
104+
return createApp(secret)
105+
}
99106

100-
const handler = lambdaRequestHandler.deferred(myAppPromise);
107+
const handler = lambdaRequestHandler.deferred(myAppPromise)
101108

102109
module.exports = { handler }
103-
104110
```
105111

106112
### Hapi
107113

108114
Please note that Hapi v19 dropped support for Node v10. The only AWS Lambda runtime that supports it is `nodejs12.x`.
109115

110116
```javascript
111-
const Hapi = require('@hapi/hapi')
112-
const lambdaRequestHandler = require('lambda-request-handler')
117+
const Hapi = require("@hapi/hapi")
118+
const lambdaRequestHandler = require("lambda-request-handler")
113119

114120
// create custom listener for Hapi
115121
const myListener = new lambdaRequestHandler.HapiListener()
116122

117123
// Pass the custom listener to Hapi.server
118124
const server = Hapi.server({
119-
listener: myListener
120-
});
125+
listener: myListener,
126+
})
121127

122128
server.route({
123-
method: 'GET',
124-
path: '/',
129+
method: "GET",
130+
path: "/",
125131
handler: (_request: any, _h: any) => {
126-
return 'Hello World!';
127-
}
128-
});
132+
return "Hello World!"
133+
},
134+
})
129135

130136
const myAppPromise = async () => {
131137
//wait for the server to initialize
132138
await server.start()
133139
// return the request listener function
134140
return myListener.handler
135-
};
141+
}
136142

137-
const handler = lambdaRequestHandler.deferred(myAppPromise);
143+
const handler = lambdaRequestHandler.deferred(myAppPromise)
138144

139145
module.exports = { handler }
140146
```
@@ -146,17 +152,17 @@ If the above file in your Lambda source was called `index.js` then the name of t
146152
This example is in Typescript
147153

148154
```typescript
149-
import lambdaRequestHandler from 'lambda-request-handler'
155+
import lambdaRequestHandler from "lambda-request-handler"
150156

151-
import { NestFactory } from '@nestjs/core';
152-
import { Module, Get, Controller } from '@nestjs/common';
153-
import { NestExpressApplication } from '@nestjs/platform-express';
157+
import { NestFactory } from "@nestjs/core"
158+
import { Module, Get, Controller } from "@nestjs/common"
159+
import { NestExpressApplication } from "@nestjs/platform-express"
154160

155161
@Controller()
156162
class AppController {
157163
@Get()
158164
render() {
159-
return { hello: 'world' };
165+
return { hello: "world" }
160166
}
161167
}
162168

@@ -167,12 +173,12 @@ class AppController {
167173
class AppModule {}
168174

169175
const getApp = async () => {
170-
const app = await NestFactory.create<NestExpressApplication>(AppModule);
176+
const app = await NestFactory.create<NestExpressApplication>(AppModule)
171177

172-
return await lambdaRequestHandler.nestHandler(app);
178+
return await lambdaRequestHandler.nestHandler(app)
173179
}
174180

175-
const handler = lambdaRequestHandler.deferred(getApp);
181+
const handler = lambdaRequestHandler.deferred(getApp)
176182

177183
module.exports = { handler }
178184
```

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
testMatch: [ "<rootDir>/test/**/*.(test|spec).ts" ]
4-
};
2+
preset: "ts-jest",
3+
testMatch: ["<rootDir>/test/**/*.(test|spec).ts"],
4+
}

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.5.1-alpha1",
44
"license": "(MIT OR Apache-2.0)",
55
"scripts": {
6+
"prettier": "prettier --write .",
7+
"prettier:ci": "prettier --check .",
68
"precompile": "rm -rf dist",
79
"compile": "tsc",
810
"test": "jest --coverage"
@@ -53,6 +55,7 @@
5355
"ejs": "^3.1.6",
5456
"express": "^4.17.3",
5557
"jest": "^27.5.1",
58+
"prettier": "^2.7.1",
5659
"ts-jest": "^27.1.4",
5760
"ts-node": "^10.7.0",
5861
"typescript": "^4.6.3"

0 commit comments

Comments
 (0)