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

Added Sample: WebApi with Express.js and EventStoreDB #47

Merged
merged 3 commits into from
Mar 16, 2024
Merged
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
12 changes: 12 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ on:
# run it on push to the default repository branch
push:
branches: [main]
paths:
- "src/**"
- "!src/docs/**"
- "!src/.vscode/**"

# run it during pull request
pull_request:
paths:
- "src/**"
- "!src/docs/**"
- "!src/.vscode/**"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

defaults:
run:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build and test Sample - WebApi with Express.js and EventStoreDB

on:
# run it on push to the default repository branch
push:
branches: [main]
paths:
- "samples/webApi/expressjs-with-esdb"
- "!src/.vscode/**"

# run it during pull request
pull_request:
paths:
- "samples/webApi/expressjs-with-esdb"
- "!src/.vscode/**"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

defaults:
run:
working-directory: ./src/samples/webApi/expressjs-with-esdb

jobs:
build-and-test-code:
name: Build application code
# use system defined below in the tests matrix
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ./src/samples/webApi/expressjs-with-esdb/.nvmrc
cache: "npm"
cache-dependency-path: "./src/samples/webApi/expressjs-with-esdb/package-lock.json"

- name: Install dependencies
run: npm ci

- name: Build TS
run: npm run build:ts

- name: Run linting (ESlint and Prettier)
run: npm run lint

- name: Build
run: npm run build

- name: Test
run: npm run test
5 changes: 5 additions & 0 deletions samples/webApi/expressjs-with-esdb/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
end_of_line = lf
11 changes: 11 additions & 0 deletions samples/webApi/expressjs-with-esdb/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/node_modules/*
# build artifacts
dist/*coverage/*

# data definition files
**/*.d.ts

# custom definition files
/src/types/

!.eslintrc.js
33 changes: 33 additions & 0 deletions samples/webApi/expressjs-with-esdb/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"env": {
"es2023": true,
"node": true
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2023,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-misused-promises": ["off"],
"@typescript-eslint/prefer-namespace-keyword": "off"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
1 change: 1 addition & 0 deletions samples/webApi/expressjs-with-esdb/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.11.1
2 changes: 2 additions & 0 deletions samples/webApi/expressjs-with-esdb/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/dist/
**/lib/
4 changes: 4 additions & 0 deletions samples/webApi/expressjs-with-esdb/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"singleQuote": true
}

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions samples/webApi/expressjs-with-esdb/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug current file",
"type": "node",
"request": "launch",

// Debug current file in VSCode
"program": "${file}",

/*
Path to tsx binary
Assuming locally installed
*/
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",

/*
Open terminal when debugging starts (Optional)
Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",

// Files to exclude from debugger (e.g. call stack)
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",

// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**"
]
},
{
"name": "Debug All Tests (Node)",
"type": "node",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"test",
"--inspect-brk=9229",
"--preserve-symlinks"
], // Use --inspect-brk for debugging
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"cwd": "${workspaceFolder}",
"sourceMaps": true,
"smartStep": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**",
"node_modules/@event-driven.io/emmett-expressjs/**/*.*"
]
}
]
}
24 changes: 24 additions & 0 deletions samples/webApi/expressjs-with-esdb/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,

"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit",
"source.addMissingImports": "always"
},

"editor.tabSize": 2,

"files.exclude": {
"**/*.tsbuildinfo": true
},
"files.eol": "\n",

"typescript.preferences.importModuleSpecifier": "relative",
"eslint.workingDirectories": [{ "mode": "auto" }],
"debug.javascript.terminalOptions": {
"nodeVersionHint": 20
}
}
13 changes: 13 additions & 0 deletions samples/webApi/expressjs-with-esdb/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build:ts:watch",
"group": "build",
"problemMatcher": [],
"label": "npm: build:ts:watch",
"detail": "tsc --watch"
}
]
}
39 changes: 39 additions & 0 deletions samples/webApi/expressjs-with-esdb/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3'

services:
#######################################################
# EventStoreDB
#######################################################
eventstoredb:
image: eventstore/eventstore:23.10.0-bookworm-slim
# use this image if you're running ARM-based proc like Apple M1
# image: eventstore/eventstore:23.10.0-alpha-arm64v8
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
- EVENTSTORE_START_STANDARD_PROJECTIONS=true
- EVENTSTORE_EXT_TCP_PORT=1113
- EVENTSTORE_HTTP_PORT=2113
- EVENTSTORE_INSECURE=true
- EVENTSTORE_ENABLE_EXTERNAL_TCP=true
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true
ports:
- '1113:1113'
- '2113:2113'
volumes:
- type: volume
source: eventstore-volume-data
target: /var/lib/eventstore
- type: volume
source: eventstore-volume-logs
target: /var/log/eventstore
networks:
- esdb_network

networks:
esdb_network:
driver: bridge

volumes:
eventstore-volume-data:
eventstore-volume-logs:
Loading