Skip to content

Commit

Permalink
feat: add expressjs adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Sep 13, 2023
1 parent 31baee3 commit 263d12d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 16 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<a name="readme-top"></a>

<!-- PROJECT SHIELDS -->

[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
Expand Down Expand Up @@ -44,6 +45,7 @@
</details>

<!-- ABOUT THE PROJECT -->

# About The Project

ExpressoTS is a [Typescript](https://www.typescriptlang.org/) + [Node.js](https://nodejs.org/en/) lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🐎
Expand Down Expand Up @@ -92,16 +94,17 @@ Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/expres

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/expressots/expressots?style=for-the-badge
[contributors-url]: https://github.com/expressots/expressots/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/expressots/expressots?style=for-the-badge
[forks-url]: https://github.com/expressots/expressots/forks
[stars-shield]: https://img.shields.io/github/stars/expressots/expressots?style=for-the-badge
[stars-url]: https://github.com/expressots/expressots/stargazers
[issues-shield]: https://img.shields.io/github/issues/expressots/expressots?style=for-the-badge
[issues-url]: https://github.com/expressots/expressots/issues
[license-shield]: https://img.shields.io/github/license/expressots/expressots?style=for-the-badge
[license-url]: https://github.com/expressots/expressots/blob/main/LICENSE

[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge
[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge
[forks-url]: https://github.com/expressots/adapter-express/forks
[stars-shield]: https://img.shields.io/github/stars/expressots/adapter-express?style=for-the-badge
[stars-url]: https://github.com/expressots/adapter-express/stargazers
[issues-shield]: https://img.shields.io/github/issues/expressots/adapter-express?style=for-the-badge
[issues-url]: https://github.com/expressots/expressadapter-expressots/issues
[license-shield]: https://img.shields.io/github/license/expressots/adapter-express?style=for-the-badge
[license-url]: https://github.com/expressots/adapter-express/blob/main/LICENSE
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://www.linkedin.com/company/expresso-ts/
[product-screenshot]: images/screenshot.png
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressots/adapter-express",
"version": "0.0.1-dev.1",
"version": "1.0.0",
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
"author": "",
"main": "./lib/cjs/index.js",
Expand Down Expand Up @@ -76,7 +76,7 @@
"devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@expressots/core": "latest",
"@expressots/core": "^1.9.0",
"@release-it/conventional-changelog": "^7.0.1",
"@types/jest": "^29.5.0",
"@types/node": "^20.4.9",
Expand All @@ -90,9 +90,6 @@
"ts-jest": "^29.0.5",
"typescript": "^5.2.2"
},
"peerDependencies": {
"@expressots/core": "latest"
},
"release-it": {
"git": {
"commitMessage": "chore(release): ${version}"
Expand Down
60 changes: 60 additions & 0 deletions src/adapter-express/application-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { provide } from "inversify-binding-decorators";

/**
* Abstract class ApplicationBase.
*
* ApplicationBase serves as the foundational structure for building
* server applications. It declares the lifecycle hooks that allow
* subclasses to configure services, handle post-server initialization,
* and perform cleanup when the server is shutting down. Extending
* classes are required to provide implementations for these methods
* to define specific behaviors for their particular use cases.
*
* @example
* class Application extends ApplicationBase {
* protected configureServices() { //... }
* protected postServerInitialization() { //... }
* protected serverShutdown() { //... }
* }
*
* @export
* @abstract
*/
@provide(ApplicationBase)
abstract class ApplicationBase {
/**
* Method to configure services that should be initialized
* before the server starts. It must be implemented by the
* extending class to set up necessary services or configurations.
* Can return a Promise for async configuration.
*
* @abstract
* @returns {void | Promise<void>}
*/
protected abstract configureServices(): void | Promise<void>;

/**
* Method to configure services or actions that should be executed
* after the server starts. It allows the extending class to perform
* any necessary operations once the server is up and running.
* Can return a Promise for async execution.
*
* @abstract
* @returns {void | Promise<void>}
*/
protected abstract postServerInitialization(): void | Promise<void>;

/**
* Method to perform any necessary actions or cleanup after the server
* is shutting down. This might include closing database connections,
* stopping background tasks, or other cleanup activities. It provides
* a clean exit point for the server.
* Can return a Promise for async cleanup.
*
* @abstract
* @returns {void | Promise<void>}
*/
protected abstract serverShutdown(): void | Promise<void>;
}

export { ApplicationBase };
2 changes: 1 addition & 1 deletion src/adapter-express/application-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
Logger,
IHandlebars,
RenderTemplateOptions,
ApplicationBase,
} from "@expressots/core";
import { IApplicationExpress } from "./application-express.interface";
import { InversifyExpressServer } from "./express-utils/inversify-express-server";
import { ApplicationBase } from "./application-base";

/**
* Enum representing possible server environments.
Expand Down

0 comments on commit 263d12d

Please sign in to comment.