-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(embed): setup lambda function for snippet renderer
- Loading branch information
1 parent
8cd7f85
commit bb6ba85
Showing
14 changed files
with
2,011 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ignorePatterns": [], | ||
"parserOptions": { | ||
"ecmaVersion": 2021, | ||
"sourceType": "module", | ||
"project": "tsconfig.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless | ||
|
||
# esbuild directories | ||
.esbuild | ||
.turbo | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Sharingan code snippet renderer | ||
|
||
## Prerequisites | ||
|
||
## Setup | ||
|
||
## Test locally | ||
|
||
### Advanced usage | ||
|
||
Any tsconfig.json can be used, but if you do, set the environment variable `TS_NODE_CONFIG` for building the application, eg `TS_NODE_CONFIG=./tsconfig.app.json npx serverless webpack` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@sharingan/code-embed", | ||
"version": "1.0.0", | ||
"description": "Generate the HTML page from a code snippet", | ||
"main": "serverless.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc", | ||
"clean": "rm -rf .turbo lib .esbuild", | ||
"lint": "eslint src serverless.ts", | ||
"invoke:local": "sls invoke local -f renderer --path src/functions/renderer/mock.json" | ||
}, | ||
"engines": { | ||
"node": ">=16.14.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@serverless/typescript": "^3.21.0", | ||
"@types/aws-lambda": "^8.10.102", | ||
"@types/node": "^17.0.45", | ||
"esbuild": "^0.15.5", | ||
"serverless": "^3.22.0", | ||
"serverless-esbuild": "^1.32.8", | ||
"ts-node": "^10.4.0", | ||
"tsconfig-paths": "^4.1.0", | ||
"typescript": "^4.8.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { AWS } from '@serverless/typescript'; | ||
|
||
import renderer from '@/functions/renderer'; | ||
|
||
const serverlessConfiguration: AWS = { | ||
custom: { | ||
esbuild: { | ||
bundle: true, | ||
concurrency: 10, | ||
define: { 'require.resolve': undefined }, | ||
exclude: ['aws-sdk'], | ||
minify: false, | ||
platform: 'node', | ||
sourcemap: true, | ||
target: 'node16', | ||
}, | ||
}, | ||
frameworkVersion: '3', | ||
// import the function via paths | ||
functions: { renderer }, | ||
package: { individually: true }, | ||
plugins: ['serverless-esbuild'], | ||
provider: { | ||
apiGateway: { | ||
minimumCompressionSize: 1024, | ||
shouldStartNameWithService: true, | ||
}, | ||
environment: { | ||
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1', | ||
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000', | ||
}, | ||
name: 'aws', | ||
runtime: 'nodejs16.x', | ||
}, | ||
service: 'code-embed', | ||
}; | ||
|
||
module.exports = serverlessConfiguration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as renderer } from './renderer'; |
10 changes: 10 additions & 0 deletions
10
apps/functions/code-embed/src/functions/renderer/handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { APIGatewayProxyEvent, APIGatewayProxyResult, Handler } from 'aws-lambda'; | ||
|
||
export const main: Handler<APIGatewayProxyEvent, APIGatewayProxyResult> = async (event) => { | ||
const snippetId = event.pathParameters['id']; | ||
|
||
return { | ||
body: snippetId, | ||
statusCode: 200, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { AWS } from '@serverless/typescript'; | ||
|
||
import { handlerPath } from '@/libs/handler-resolver'; | ||
|
||
type LambdaEventHandler = Pick<AWS['functions'][number], 'events' | 'handler'>; | ||
|
||
export default { | ||
events: [ | ||
{ | ||
http: { | ||
method: 'get', | ||
path: 'snippets/{id+}', | ||
request: { | ||
parameters: { | ||
paths: { | ||
id: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
handler: `${handlerPath(__dirname)}/handler.main`, | ||
} as LambdaEventHandler; |
11 changes: 11 additions & 0 deletions
11
apps/functions/code-embed/src/functions/renderer/mock.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "text/html" | ||
}, | ||
"pathParameters": { | ||
"id": "/path/to/resource" | ||
}, | ||
"queryStringParameters": { | ||
"foo": "bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const handlerPath = (context: string) => { | ||
return `${context.split(process.cwd())[1].substring(1).replace(/\\/g, '/')}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": "./tsconfig.paths.json", | ||
"compilerOptions": { | ||
"lib": ["ESNext"], | ||
"moduleResolution": "node", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"removeComments": true, | ||
"sourceMap": true, | ||
"target": "ES2020", | ||
"outDir": "lib", | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*.ts", "serverless.ts"], | ||
"exclude": [ | ||
"node_modules/**/*", | ||
".serverless/**/*", | ||
".webpack/**/*", | ||
"_warmup/**/*", | ||
".vscode/**/*" | ||
], | ||
"ts-node": { | ||
"require": ["tsconfig-paths/register"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/functions/*": ["src/functions/*"], | ||
"@/libs/*": ["src/libs/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.