Skip to content

Commit 14aa2c5

Browse files
authored
fix: change env and proxy to getter and setter (#9)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced GitHub Actions workflow for automatic publishing on push and pull requests. - **Enhancements** - Added new CI script to streamline the build and publishing process. - Improved type safety and code quality with updated devDependencies. - **Refactor** - Updated class properties in the `Application` class to use getter and setter methods for better encapsulation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0543aa7 commit 14aa2c5

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

.github/workflows/pkg.pr.new.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish Any Commit
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- run: corepack enable
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
17+
- name: Install dependencies
18+
run: npm install
19+
20+
- name: Build
21+
run: npm run prepublishOnly
22+
23+
- run: npx pkg-pr-new publish

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"description": "Koa web app framework for https://eggjs.org",
1111
"scripts": {
1212
"test": "npm run lint -- --fix && egg-bin test",
13-
"ci": "npm run lint && egg-bin cov && npm run prepublishOnly",
13+
"ci": "npm run lint && egg-bin cov && npm run prepublishOnly && attw --pack",
1414
"lint": "eslint src test",
1515
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS",
1616
"prepublishOnly": "tshy && tshy-after"
@@ -52,6 +52,7 @@
5252
"vary": "^1.1.2"
5353
},
5454
"devDependencies": {
55+
"@arethetypeswrong/cli": "^0.15.3",
5556
"@eggjs/tsconfig": "^1.3.3",
5657
"@types/content-type": "^1.1.8",
5758
"@types/delegates": "^1.0.3",
@@ -71,7 +72,7 @@
7172
"@types/vary": "^1.1.3",
7273
"egg-bin": "^6.4.0",
7374
"eslint": "^8.41.0",
74-
"eslint-config-egg": "^13.1.0",
75+
"eslint-config-egg": "14",
7576
"mm": "^3.3.0",
7677
"supertest": "^3.1.0",
7778
"tsd": "^0.31.0",

src/application.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export class Application extends Emitter {
3535
*/
3636
static HttpError = HttpError;
3737

38-
proxy: boolean;
38+
protected _proxy: boolean;
39+
protected _env: string;
3940
subdomainOffset: number;
4041
proxyIpHeader: string;
4142
maxIpsCount: number;
42-
env: string;
4343
keys?: string[];
4444
middleware: MiddlewareFunc[];
4545
ctxStorage: AsyncLocalStorage<ContextDelegation>;
@@ -73,11 +73,11 @@ export class Application extends Emitter {
7373
}) {
7474
super();
7575
options = options || {};
76-
this.proxy = options.proxy || false;
76+
this._proxy = options.proxy || false;
7777
this.subdomainOffset = options.subdomainOffset || 2;
7878
this.proxyIpHeader = options.proxyIpHeader || 'X-Forwarded-For';
7979
this.maxIpsCount = options.maxIpsCount || 0;
80-
this.env = options.env || process.env.NODE_ENV || 'development';
80+
this._env = options.env || process.env.NODE_ENV || 'development';
8181
if (options.keys) this.keys = options.keys;
8282
this.middleware = [];
8383
this.ctxStorage = getAsyncLocalStorage();
@@ -90,6 +90,20 @@ export class Application extends Emitter {
9090
this.response = this.ResponseClass.prototype;
9191
}
9292

93+
get env() {
94+
return this._env;
95+
}
96+
set env(value: string) {
97+
this._env = value;
98+
}
99+
100+
get proxy() {
101+
return this._proxy;
102+
}
103+
set proxy(value: boolean) {
104+
this._proxy = value;
105+
}
106+
93107
/**
94108
* Shorthand for:
95109
*

0 commit comments

Comments
 (0)