-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move cors plugin to @artusx/core
- Loading branch information
Showing
20 changed files
with
156 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -17,18 +17,21 @@ | |
"author": "Suyi <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@artusx/plugin-application-http": "workspace:*" | ||
"@artus/core": "^2.x", | ||
"@artus/pipeline": "^0.2", | ||
"@artusx/plugin-application-http": "workspace:*", | ||
"@koa/cors": "~5.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@artus/core": "^2.x", | ||
"@artus/pipeline": "^0.2" | ||
"reflect-metadata": "^0.1.13" | ||
}, | ||
"devDependencies": { | ||
"@artus/tsconfig": "^1.0.1", | ||
"@types/node": "^18.11.17", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.5.0", | ||
"typescript": "^4.9.4" | ||
"typescript": "^4.9.4", | ||
"@types/koa__cors": "~5.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
|
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 |
---|---|---|
@@ -1 +1,33 @@ | ||
export default {}; | ||
import { | ||
Inject, | ||
ArtusInjectEnum, | ||
ArtusApplication, | ||
ApplicationLifecycle, | ||
LifecycleHook, | ||
LifecycleHookUnit | ||
} from '@artus/core'; | ||
|
||
import cors from '@koa/cors'; | ||
import KoaApplication from '@artusx/plugin-application-http/lib/koa/application'; | ||
|
||
@LifecycleHookUnit() | ||
export default class ArtusXCoreLifecycle implements ApplicationLifecycle { | ||
@Inject(ArtusInjectEnum.Application) | ||
private readonly app: ArtusApplication; | ||
|
||
get koa(): KoaApplication { | ||
return this.app.container.get(KoaApplication); | ||
} | ||
|
||
@LifecycleHook() | ||
async didLoad() { | ||
this.koa.use( | ||
cors({ | ||
credentials: true, | ||
origin(ctx) { | ||
return ctx.get('Origin') || 'localhost'; | ||
} | ||
}) | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
port: 7001, | ||
middlewares: [] | ||
koa: { | ||
port: 7001 | ||
} | ||
}; |
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 @@ | ||
export enum ArtusXInjectEnum { | ||
// application-http | ||
Koa = 'ARTUSX_KOA', | ||
Pipeline = 'ARTUSX_PIPELINE', | ||
|
||
// redis | ||
Redis = 'ARTUSX_REDIS', | ||
|
||
// sequelize | ||
Sequelize = 'ARTUSX_SEQUELIZE' | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
"author": "Suyi <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@koa/cors": "^5.0.0", | ||
"@koa/router": "^12.0.1", | ||
"koa": "^2.15.0", | ||
"@artus/core": "^2.x", | ||
|
@@ -30,7 +29,6 @@ | |
"devDependencies": { | ||
"@artus/tsconfig": "^1.0.1", | ||
"@types/koa": "^2.13.12", | ||
"@types/koa__cors": "^5.0.0", | ||
"@types/koa__router": "^12.0.4", | ||
"@types/node": "^18.11.17", | ||
"tslib": "^2.5.0", | ||
|
10 changes: 8 additions & 2 deletions
10
packages/plugins/application-http/src/config/config.default.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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
export default { | ||
port: 7001, | ||
middlewares: [] | ||
artusx: { | ||
middlewares: [] | ||
}, | ||
|
||
koa: { | ||
port: 7001, | ||
middlewares: [] | ||
} | ||
}; |
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,5 @@ | ||
export enum ArtusXInjectEnum { | ||
Koa = 'ARTUSX_KOA', | ||
KoaRouter = 'ARTUSX_KOA_ROUTER', | ||
Pipeline = 'ARTUSX_PIPELINE' | ||
} |
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 @@ | ||
import Koa from 'koa'; | ||
import { Injectable, ScopeEnum } from '@artus/core'; | ||
import { ArtusXInjectEnum } from '../constants'; | ||
|
||
@Injectable({ | ||
id: ArtusXInjectEnum.Koa, | ||
scope: ScopeEnum.SINGLETON | ||
}) | ||
export default class KoaApplication extends Koa {} |
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 @@ | ||
import Router from '@koa/router'; | ||
import { Injectable, ScopeEnum } from '@artus/core'; | ||
import { ArtusXInjectEnum } from '../constants'; | ||
|
||
@Injectable({ | ||
id: ArtusXInjectEnum.KoaRouter, | ||
scope: ScopeEnum.SINGLETON | ||
}) | ||
export default class KoaRouter extends Router {} |
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
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
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 |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import { Server } from 'http'; | ||
import { LifecycleHookUnit, LifecycleHook } from '@artus/core'; | ||
import { ApplicationLifecycle } from '@artus/core'; | ||
import { ArtusApplication, Inject, ArtusInjectEnum } from '@artus/core'; | ||
|
||
import { ArtusXInjectEnum } from './constants'; | ||
import Redis, { RedisConfig } from './client'; | ||
|
||
export let server: Server; | ||
|
||
@LifecycleHookUnit() | ||
export default class RedisLifecycle implements ApplicationLifecycle { | ||
@Inject(ArtusInjectEnum.Application) | ||
app: ArtusApplication; | ||
|
||
@LifecycleHook() | ||
async willReady() { | ||
const redis = this.app.container.get('ARTUS_REDIS') as Redis; | ||
const redis = this.app.container.get(ArtusXInjectEnum.Redis) as Redis; | ||
await redis.init(this.app.config.redis as RedisConfig); | ||
} | ||
} |
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
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 enum ArtusXInjectEnum { | ||
Redis = 'ARTUSX_REDIS' | ||
} |
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.