Skip to content
Open
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
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*.js
node_modules
dist
serverless.ts
92 changes: 92 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"standard"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"eslint-plugin-import-helpers"
],
"rules": {
"camelcase": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"space-before-function-paren": "error",
"@typescript-eslint/explicit-module-boundary-types": "warn",
"import/no-unresolved": "error",
"no-unused-vars": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "_"
}
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "interface",
"format": [
"PascalCase"
],
"custom": {
"regex": "^I[A-Z]",
"match": true
}
}
],
"class-methods-use-this": "off",
"import/prefer-default-export": "off",
"no-shadow": "off",
"no-console": "off",
"no-useless-constructor": "off",
"no-empty-function": "off",
"lines-between-class-members": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"import-helpers/order-imports": [
"warn",
{
"newlinesBetween": "always",
"groups": [
"module",
"/^@/",
[
"parent",
"sibling",
"index"
]
],
"alphabetize": {
"order": "asc",
"ignoreCase": true
}
}
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"**/*.spec.js"
]
}
]
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
.dynamodb

# esbuild directories
.esbuild
3 changes: 3 additions & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lts/fermium
./dynamodb
./esbuild
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "test-back-end",
"version": "1.0.0",
"description": "Serverless aws-nodejs-typescript template",
"main": "serverless.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": ">=14.15.0"
},
"dependencies": {
"@middy/core": "^2.5.3",
"@middy/http-json-body-parser": "^2.5.3",
"aws-lambda": "^1.0.7",
"aws-sdk": "^2.1167.0",
"bcryptjs": "^2.4.3",
"dayjs": "^1.11.3",
"jsonwebtoken": "^8.5.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"@serverless/typescript": "^3.0.0",
"@types/aws-lambda": "^8.10.71",
"@types/bcryptjs": "^2.4.2",
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "^14.14.25",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"esbuild": "^0.14.48",
"eslint": "^8.19.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-import-helpers": "^1.2.1",
"eslint-plugin-n": "^15.2.4",
"eslint-plugin-promise": "^6.0.0",
"json-schema-to-ts": "^1.5.0",
"serverless": "^3.0.0",
"serverless-dynamodb-local": "^0.2.40",
"serverless-esbuild": "^1.23.3",
"serverless-middleware": "^3.0.0",
"serverless-offline": "^8.8.0",
"ts-node": "^10.4.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.3"
},
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
"license": "MIT"
}
221 changes: 221 additions & 0 deletions serverless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import type { AWS } from '@serverless/typescript';

const serverlessConfiguration: AWS = {
service: 'test-back-end',
frameworkVersion: '3',
plugins: [
'serverless-esbuild',
'serverless-dynamodb-local',
'serverless-middleware',
'serverless-offline'
],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
},
httpApi: {
cors: true,
authorizers: {
jwtAuthenticateLambda: {
type: 'request',
functionName: 'authenticateProxy'
}
}
}
},
// import the function via paths
functions: {
authenticateProxy: {
name: 'lambda-authenticate',
handler: "src/functions/authenticate-volunteer-proxy.handler"
},
createVolunteer: {
handler: "src/functions/create-volunteer.handler",
events: [
{
http: {
path: "/create/volunteer",
method: "post",

cors: true
}
}
]
},
showOneVolunteer: {
handler: "src/functions/show-one-volunteer.handler",
events: [
{
http: {
path: "/show/volunteer/{email}",
method: "get",

cors: true,
authorizer: {
name: "authenticateProxy"
}
}
}
]
},
updateVolunteer: {
handler: "src/functions/update-volunteer.handler",
events: [
{
http: {
path: "/update/volunteer",
method: "put",

cors: true,
}
}
]
},
deleteVolunteer: {
handler: "src/functions/delete-volunteer.handler",
events: [
{
http: {
path: "/delete/volunteer",
method: "delete",

cors: true,
}
}
]
},
authenticateVolunteer: {
handler: "src/functions/authenticate-volunteer.handler",
events: [
{
http: {
path: "/authenticate/volunteer",
method: "post",

cors: true,
}
}
]
}
},
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node14',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
},
dynamodb: {
stages: ["dev", "local"],
start: {
port: 8000,
inMemory: true,
migrate: true
}
}
},
resources: {
Resources: {
dbVolunteersTable: {
Type: "AWS::DynamoDB::Table",
Properties: {
TableName: "volunteers",
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
AttributeDefinitions: [
{
AttributeName: "email",
AttributeType: "S"
}
],
KeySchema: [
{
AttributeName: "email",
KeyType: "HASH"
}
]
}
},
dbVolunteersTokenTable: {
Type: "AWS::DynamoDB::Table",
Properties: {
TableName: "volunteers_token",
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
AttributeDefinitions: [
{
AttributeName: "id",
AttributeType: "S"
},
{
AttributeName: "volunteer_id",
AttributeType: "S"
},
{
AttributeName: "refresh_token",
AttributeType: "S"
}
],
KeySchema: [
{
AttributeName: "id",
KeyType: "HASH"
}
],
GlobalSecondaryIndexes: [
{
IndexName: "VolunteerId",
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
KeySchema: [
{
AttributeName: "volunteer_id",
KeyType: "HASH"
}
],
Projection: {
ProjectionType: "ALL"
}
},
{
IndexName: "RefreshToken",
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
KeySchema: [
{
AttributeName: "refresh_token",
KeyType: "HASH"
}
],
Projection: {
ProjectionType: "ALL"
}
}
]
}
}
}
}
};

module.exports = serverlessConfiguration;
Loading