Skip to content

Commit

Permalink
feat: add plugin-express
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Jan 16, 2024
1 parent b843e61 commit c565e25
Show file tree
Hide file tree
Showing 29 changed files with 922 additions and 86 deletions.
407 changes: 321 additions & 86 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/apps/artusx-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist"
},
Expand Down
27 changes: 27 additions & 0 deletions packages/apps/artusx-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ArtusX-API

> undefined project with web-server powered by ArtusX.
## Usage

### Development

```bash
pnpm i
pnpm run dev
```

### Production

```bash
pnpm run start

# nohup
nohup pnpm run start &
```

### Requirement

- Docker
- Node.js 18.x
- Typescript 4.x+
25 changes: 25 additions & 0 deletions packages/apps/artusx-legacy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "artusx-legacy",
"version": "1.0.0",
"description": "legacy for artusx",
"main": "index.js",
"scripts": {
"build": "",
"dev": "npx nodemon src/bootstrap.ts"
},
"dependencies": {
"@artus/core": "^2.x",
"@artusx/plugin-express": "workspace:*",
"@artusx/utils": "workspace:*",
"nodemon": "~3.0.2",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@artus/tsconfig": "~1.0.1",
"@types/node": "~20.10.6",
"nodemon": "~3.0.2",
"ts-node": "~10.9.2",
"tslib": "~2.6.2",
"typescript": "~5.3.3"
}
}
11 changes: 11 additions & 0 deletions packages/apps/artusx-legacy/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from 'path';
import { Application } from '@artusx/utils';

(async () => {
await Application.start({
root: path.resolve(__dirname),
configDir: 'config'
});

// console.log(app.config);
})();
1 change: 1 addition & 0 deletions packages/apps/artusx-legacy/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
6 changes: 6 additions & 0 deletions packages/apps/artusx-legacy/src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
express: {
enable: true,
package: '@artusx/plugin-express'
}
};
10 changes: 10 additions & 0 deletions packages/apps/artusx-legacy/src/controller/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// import { GET, HTTPController } from '../types';
// import type { ArtusxContext } from '../types';

// @HTTPController()
// export default class HomeController {
// @GET('/')
// async home(ctx: ArtusxContext) {
// ctx.body = 'Hello World';
// }
// }
38 changes: 38 additions & 0 deletions packages/apps/artusx-legacy/src/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
ArtusApplication,
ArtusInjectEnum,
ApplicationLifecycle,
Inject,
LifecycleHook,
LifecycleHookUnit
} from '@artus/core';
import { ArtusXInjectEnum, IExpressClient } from './types';

@LifecycleHookUnit()
export default class ExpressLifecycle implements ApplicationLifecycle {
@Inject(ArtusInjectEnum.Application)
app: ArtusApplication;

@Inject(ArtusXInjectEnum.Express)
express: IExpressClient;

@LifecycleHook()
async willReady() {
const router = this.express.router;
router.use((req, res, next) => {
console.log('%s %s %s', req.method, req.url, req.path);
res.locals.method = req.method;
next();
});

router.get('/', (_req, res) => {
console.log(res.locals);
res.send('router - /, powered by express.js');
});

router.get('/get', (_req, res) => {
console.log(res.locals);
res.send('router - /get , powered by express.js');
});
}
}
2 changes: 2 additions & 0 deletions packages/apps/artusx-legacy/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@artusx/plugin-express';
export { default as IExpressClient } from '@artusx/plugin-express/client';
12 changes: 12 additions & 0 deletions packages/apps/artusx-legacy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@artus/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist"
},
"include": ["src/**/*.ts", "src/**/*.json"]
}
1 change: 1 addition & 0 deletions packages/apps/artusx-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist"
},
Expand Down
1 change: 1 addition & 0 deletions packages/libs/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "lib"
},
Expand Down
1 change: 1 addition & 0 deletions packages/libs/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "lib"
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/application-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"strictNullChecks": true,
"resolveJsonModule": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "lib"
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/express/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
3 changes: 3 additions & 0 deletions packages/plugins/express/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ArtusX plugin redis

> https://github.com/thonatos/artusx
3 changes: 3 additions & 0 deletions packages/plugins/express/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "express"
}
56 changes: 56 additions & 0 deletions packages/plugins/express/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@artusx/plugin-express",
"version": "1.0.1-dev.16",
"description": "express plugin for artusx",
"keywords": [
"artus.js"
],
"license": "MIT",
"author": "Suyi <[email protected]>",
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./constants": {
"types": "./lib/constants.d.ts",
"default": "./lib/constants.js"
},
"./client": {
"types": "./lib/client.d.ts",
"default": "./lib/client.js"
},
"./lifecycle": {
"types": "./lib/lifecycle.d.ts",
"default": "./lib/lifecycle.js"
}
},
"main": "lib/index.js",
"types": "lib/index.d.js",
"files": [
"lib"
],
"scripts": {
"build": "npm run tsc && npm run build:metadata",
"build:metadata": "cp meta.json ./lib/meta.json",
"tsc": "rm -rf lib && tsc"
},
"dependencies": {
"@artus/core": "^2.x",
"@artus/pipeline": "^0.2",
"express": "~4.18.2"
},
"devDependencies": {
"@artus/tsconfig": "^1.0.1",
"@types/express": "~4.17.21",
"@types/node": "^18.11.17",
"tslib": "^2.5.0",
"typescript": "^4.9.4"
},
"peerDependencies": {
"reflect-metadata": "^0.1.13"
},
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit c565e25

Please sign in to comment.