Skip to content

Commit

Permalink
fix: change env and proxy to getter and setter (#9)
Browse files Browse the repository at this point in the history
<!-- 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 -->
  • Loading branch information
fengmk2 authored Jun 30, 2024
1 parent 0543aa7 commit 14aa2c5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly

- run: npx pkg-pr-new publish
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"description": "Koa web app framework for https://eggjs.org",
"scripts": {
"test": "npm run lint -- --fix && egg-bin test",
"ci": "npm run lint && egg-bin cov && npm run prepublishOnly",
"ci": "npm run lint && egg-bin cov && npm run prepublishOnly && attw --pack",
"lint": "eslint src test",
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS",
"prepublishOnly": "tshy && tshy-after"
Expand Down Expand Up @@ -52,6 +52,7 @@
"vary": "^1.1.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@eggjs/tsconfig": "^1.3.3",
"@types/content-type": "^1.1.8",
"@types/delegates": "^1.0.3",
Expand All @@ -71,7 +72,7 @@
"@types/vary": "^1.1.3",
"egg-bin": "^6.4.0",
"eslint": "^8.41.0",
"eslint-config-egg": "^13.1.0",
"eslint-config-egg": "14",
"mm": "^3.3.0",
"supertest": "^3.1.0",
"tsd": "^0.31.0",
Expand Down
22 changes: 18 additions & 4 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export class Application extends Emitter {
*/
static HttpError = HttpError;

proxy: boolean;
protected _proxy: boolean;
protected _env: string;
subdomainOffset: number;
proxyIpHeader: string;
maxIpsCount: number;
env: string;
keys?: string[];
middleware: MiddlewareFunc[];
ctxStorage: AsyncLocalStorage<ContextDelegation>;
Expand Down Expand Up @@ -73,11 +73,11 @@ export class Application extends Emitter {
}) {
super();
options = options || {};
this.proxy = options.proxy || false;
this._proxy = options.proxy || false;
this.subdomainOffset = options.subdomainOffset || 2;
this.proxyIpHeader = options.proxyIpHeader || 'X-Forwarded-For';
this.maxIpsCount = options.maxIpsCount || 0;
this.env = options.env || process.env.NODE_ENV || 'development';
this._env = options.env || process.env.NODE_ENV || 'development';
if (options.keys) this.keys = options.keys;
this.middleware = [];
this.ctxStorage = getAsyncLocalStorage();
Expand All @@ -90,6 +90,20 @@ export class Application extends Emitter {
this.response = this.ResponseClass.prototype;
}

get env() {
return this._env;
}
set env(value: string) {
this._env = value;
}

get proxy() {
return this._proxy;
}
set proxy(value: boolean) {
this._proxy = value;
}

/**
* Shorthand for:
*
Expand Down

0 comments on commit 14aa2c5

Please sign in to comment.