Skip to content

Commit 097a786

Browse files
jcubicjames-pre
andauthored
Merge PR James pre/fix (#24)
BREAKING CHANGE: Rewrite to ESM, remove broken deps * Updated npm scripts Updated package contributors Updated semantic-release Remove more unused deps * Added `status` subcommand Fixed 403 for landing page * Added restart flag * Fixes, use `beforeExit` * Minor changes * Keep search params * Fix `fetch` * fix build * update Node.js in CI/CD * Update readme * Added small API section * Add back support for middleware * Revert readme changes * formatting --------- Co-authored-by: James Prevett <[email protected]>
1 parent aa4c71a commit 097a786

File tree

13 files changed

+4055
-6224
lines changed

13 files changed

+4055
-6224
lines changed

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": false,
3+
"tabWidth": 2,
4+
"printWidth": 120,
5+
"singleQuote": true
6+
}

.vscode/launch.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
{
2-
// Use IntelliSense to learn about possible Node.js debug attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "launch",
10-
"name": "Launch micro",
11-
"program": "${workspaceRoot}/node_modules/micro/bin/micro.js",
12-
"args": [
13-
"index.js"
14-
]
15-
}
16-
]
17-
}
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch micro",
11+
"program": "${workspaceRoot}/node_modules/micro/bin/micro.js",
12+
"args": ["index.js"]
13+
}
14+
]
15+
}

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
44

55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

7-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ npm install @isomorphic-git/cors-proxy
1818
Start proxy on default port 9999:
1919

2020
```sh
21-
cors-proxy start
21+
cors-proxy run
2222
```
2323

2424
Start proxy on a custom port:
2525

2626
```sh
27-
cors-proxy start -p 9889
27+
cors-proxy run -p 9889
2828
```
2929

30-
Start proxy in daemon mode. It will write the PID of the daemon process to `$PWD/cors-proxy.pid`:
30+
Start proxy in daemon mode.
3131

3232
```sh
33-
cors-proxy start -d
33+
cors-proxy start
3434
```
3535

36-
Kill the process with the PID specified in `$PWD/cors-proxy.pid`:
36+
Kill the daemon process:
3737

3838
```sh
3939
cors-proxy stop
@@ -42,35 +42,35 @@ cors-proxy stop
4242
### CLI configuration
4343

4444
Environment variables:
45+
4546
- `PORT` the port to listen to (if run with `npm start`)
4647
- `ALLOW_ORIGIN` the value for the 'Access-Control-Allow-Origin' CORS header
4748
- `INSECURE_HTTP_ORIGINS` comma separated list of origins for which HTTP should be used instead of HTTPS (added to make developing against locally running git servers easier)
4849

49-
5050
## Middleware usage
5151

5252
You can also use the `cors-proxy` as a middleware in your own server.
5353

5454
```js
55-
const express = require('express')
56-
const corsProxy = require('@isomorphic-git/cors-proxy/middleware.js')
55+
import express from 'express';
56+
import corsProxy from '@isomorphic-git/cors-proxy';
5757

58-
const app = express()
59-
const options = {}
60-
61-
app.use(corsProxy(options))
58+
const app = express();
59+
const options = {};
6260

61+
app.use(corsProxy(options));
6362
```
6463

6564
### Middleware configuration
6665

67-
*The middleware doesn't use the environment variables.* The options object supports the following properties:
66+
_The middleware doesn't use the environment variables._ The options object supports the following properties:
6867

6968
- `origin`: _string_. The value for the 'Access-Control-Allow-Origin' CORS header
7069
- `insecure_origins`: _string[]_. Array of origins for which HTTP should be used instead of HTTPS (added to make developing against locally running git servers easier)
7170
- `authorization`: _(req, res, next) => void_. A middleware function you can use to handle custom authorization. Is run after filtering for git-like requests and handling CORS but before the request is proxied.
7271

7372
_Example:_
73+
7474
```ts
7575
app.use(
7676
corsProxy({
@@ -83,7 +83,7 @@ app.use(
8383
return res.status(401).send("Unable to authenticate you with [Company]'s git proxy");
8484
}
8585
},
86-
})
86+
}),
8787
);
8888

8989
// Only requests with a valid JSON Web Token will be proxied
@@ -111,29 +111,30 @@ function getAuthorizedUser(req: Request, header: string = 'Authorization') {
111111
There is no official chart for this project, helm or otherwise. You can make your own, but keep in mind cors-proxy uses the Micro server, which will return a 403 error for any requests that do not have the user agent header.
112112

113113
_Example:_
114+
114115
```yaml
115-
containers:
116-
- name: cors-proxy
117-
image: node:lts-alpine
118-
env:
119-
- name: ALLOW_ORIGIN
120-
value: https://mydomain.com
121-
command:
122-
- npx
123-
args:
124-
- '@isomorphic-git/cors-proxy'
125-
- start
126-
ports:
127-
- containerPort: 9999
128-
hostPort: 9999
129-
name: proxy
130-
protocol: TCP
131-
livenessProbe:
132-
tcpSocket:
133-
port: proxy
134-
readinessProbe:
135-
tcpSocket:
136-
port: proxy
116+
containers:
117+
- name: cors-proxy
118+
image: node:lts-alpine
119+
env:
120+
- name: ALLOW_ORIGIN
121+
value: https://mydomain.com
122+
command:
123+
- npx
124+
args:
125+
- '@isomorphic-git/cors-proxy'
126+
- start
127+
ports:
128+
- containerPort: 9999
129+
hostPort: 9999
130+
name: proxy
131+
protocol: TCP
132+
livenessProbe:
133+
tcpSocket:
134+
port: proxy
135+
readinessProbe:
136+
tcpSocket:
137+
port: proxy
137138
```
138139
139140
## License

allow-request.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

azure-pipelines.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
jobs:
2-
- job: Linux
2+
- job: Linux
33

4-
pool:
5-
vmImage: 'ubuntu-latest'
4+
pool:
5+
vmImage: 'ubuntu-latest'
66

7-
steps:
8-
- task: NodeTool@0
9-
inputs:
10-
versionSpec: '10.x'
11-
displayName: 'Install Node.js'
7+
steps:
8+
- task: NodeTool@0
9+
inputs:
10+
versionSpec: '22.x'
11+
displayName: 'Install Node.js'
1212

13-
- script: npm ci
14-
displayName: 'Install dependencies'
13+
- script: npm ci
14+
displayName: 'Install dependencies'
1515

16-
- script: npm pack
17-
displayName: 'Prepare installable tarball'
18-
condition: succeededOrFailed()
16+
- script: npm pack
17+
displayName: 'Prepare installable tarball'
18+
condition: succeededOrFailed()
1919

20-
- task: PublishBuildArtifacts@1
21-
displayName: 'Save npm-tarball.tgz'
22-
condition: and(succeededOrFailed(), ne(variables['system.pullrequest.isfork'], true))
23-
inputs:
24-
artifactName: 'npm-tarball.tgz'
25-
PathtoPublish: '$(System.DefaultWorkingDirectory)/isomorphic-git-cors-proxy-0.0.0-development.tgz'
20+
- task: PublishBuildArtifacts@1
21+
displayName: 'Save npm-tarball.tgz'
22+
condition: and(succeededOrFailed(), ne(variables['system.pullrequest.isfork'], true))
23+
inputs:
24+
artifactName: 'npm-tarball.tgz'
25+
PathtoPublish: '$(System.DefaultWorkingDirectory)/isomorphic-git-cors-proxy-0.0.0-development.tgz'
2626

27-
- script: npm run semantic-release
28-
displayName: 'Publish to npm'
29-
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
30-
env:
31-
GH_TOKEN: $(GITHUB_TOKEN)
32-
NPM_TOKEN: $(Npm.Token)
27+
- script: npm run semantic-release
28+
displayName: 'Publish to npm'
29+
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
30+
env:
31+
GH_TOKEN: $(GITHUB_TOKEN)
32+
NPM_TOKEN: $(Npm.Token)

0 commit comments

Comments
 (0)