-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cfb49b
commit e9764de
Showing
31 changed files
with
353 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ node_modules/ | |
|
||
# PipyJS | ||
config/pipy-codebases/ | ||
config/pjs/ | ||
config/website/ | ||
*.yaml | ||
|
||
# Temp | ||
|
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
14 changes: 0 additions & 14 deletions
14
packages/server/config/pipy-codebases/tunnelExternal/ip-list.json
This file was deleted.
Oops, something went wrong.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
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,32 @@ | ||
#!/bin/bash | ||
sleep 1 | ||
|
||
curl -X POST http://localhost:6060/api/v1/repo/website | ||
|
||
curl -X POST http://localhost:6060/api/v1/repo-files/website/main.js --data-binary "@../pjs/main.js" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/config.js --data-binary "@../pjs/config.js" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/config.json --data-binary "@../pjs/config.json" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/plugins/balancer.js --data-binary "@../pjs/plugins/balancer.js" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/plugins/default.js --data-binary "@../pjs/plugins/default.js" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/plugins/router.js --data-binary "@../pjs/plugins/router.js" | ||
curl -X POST http://localhost:6060/api/v1/repo-files/website/plugins/serve-files.js --data-binary "@../pjs/plugins/serve-files.js" | ||
curl -X PATCH http://localhost:6060/api/v1/repo/website --data-raw '{"version":"1"}' | ||
|
||
function getdir(){ | ||
for element in `ls $1` | ||
do | ||
dir_or_file=$1"/"$element | ||
if [ -d $dir_or_file ] | ||
then | ||
getdir $dir_or_file | ||
else | ||
file=${dir_or_file/../} | ||
echo added $file | ||
curl -X POST "http://localhost:6060/api/v1/repo-files/website"$file --data-binary "@"$dir_or_file | ||
fi | ||
done | ||
} | ||
root_dir="../www" | ||
getdir $root_dir | ||
|
||
curl -X PATCH http://localhost:6060/api/v1/repo/website --data-raw '{"version":"2"}' |
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,4 @@ | ||
#!/bin/bash | ||
nohup sh init-repo.sh >/dev/null 2>&1 & | ||
|
||
./pipy |
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,2 @@ | ||
#!/bin/bash | ||
./pipy http://localhost:6060/repo/website/ |
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,2 @@ | ||
#!/bin/bash | ||
./pipy ../pjs/main.js |
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 @@ | ||
JSON.decode(pipy.load('config.json')) |
Empty file.
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,38 @@ | ||
(( | ||
config = JSON.decode(pipy.load('config.json')), | ||
) => pipy({ | ||
_certificates: Object.fromEntries( | ||
Object.entries(config.certificates).map( | ||
([k, v]) => [ | ||
k, { | ||
cert: new crypto.CertificateChain(os.readFile(v.cert)), | ||
key: new crypto.PrivateKey(os.readFile(v.key)), | ||
} | ||
] | ||
) | ||
), | ||
|
||
}) | ||
|
||
.export('main', { | ||
__route: undefined, | ||
__isTLS: false, | ||
}) | ||
|
||
.listen(config.listen) | ||
.link('inbound-http') | ||
|
||
.listen(config.listenTLS || 0 ) | ||
.onStart(() => void (__isTLS = true)) | ||
.acceptTLS({ | ||
certificate: (sni, cert) => ( | ||
sni && Object.entries(_certificates).find(([k, v]) => new RegExp(k).test(sni))?.[1] | ||
) | ||
}).to('inbound-http') | ||
|
||
.pipeline('inbound-http') | ||
.demuxHTTP().to( | ||
$ => $.chain(config.plugins) | ||
) | ||
|
||
)() |
37 changes: 37 additions & 0 deletions
37
packages/server/config/website/template/pjs/plugins/balancer.js
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,37 @@ | ||
(( | ||
config = pipy.solve('config.js'), | ||
policies = { | ||
'RoundRobinLoadBalancer': algo.RoundRobinLoadBalancer, | ||
'LeastWorkLoadBalancer': algo.LeastWorkLoadBalancer, | ||
'HashingLoadBalancer': algo.HashingLoadBalancer, | ||
}, | ||
balancers = ( | ||
Object.fromEntries( | ||
Object.entries(config.upstreams).map( | ||
([k, v]) => [ | ||
k, new policies[v.policy](v.targets) | ||
] | ||
) | ||
) | ||
), | ||
|
||
) => pipy({ | ||
_target: undefined, | ||
}) | ||
|
||
.import({ | ||
__route: 'main', | ||
}) | ||
|
||
.pipeline() | ||
.branch( | ||
() => Boolean(_target = balancers[__route]?.next?.()), ( | ||
$ => $.muxHTTP(() => _target).to( | ||
$ => $.connect(() => _target.id) | ||
) | ||
), ( | ||
$ => $.chain() | ||
) | ||
) | ||
|
||
)() |
7 changes: 7 additions & 0 deletions
7
packages/server/config/website/template/pjs/plugins/default.js
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,7 @@ | ||
(config => | ||
pipy() | ||
.pipeline() | ||
.replaceMessage( | ||
new Message({ status: 404 }, 'No handler') | ||
) | ||
)() |
40 changes: 40 additions & 0 deletions
40
packages/server/config/website/template/pjs/plugins/router.js
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,40 @@ | ||
(( | ||
// config = JSON.decode(pipy.load('config.json')), | ||
config = pipy.solve('config.js'), | ||
|
||
router = new algo.URLRouter( | ||
Object.fromEntries( | ||
Object.entries(config.endpoints).map( | ||
([k, { route, rewrite }]) => [ | ||
k, { route, rewrite: rewrite && [new RegExp(rewrite[0]), rewrite[1]] } | ||
] | ||
) | ||
) | ||
), | ||
|
||
) => pipy() | ||
|
||
.import({ | ||
__route: 'main', | ||
}) | ||
|
||
.pipeline() | ||
.handleMessageStart( | ||
msg => ( | ||
(( | ||
r = router.find( | ||
msg.head.headers.host, | ||
msg.head.path, | ||
) | ||
) => ( | ||
__route = r?.route, | ||
r?.rewrite && ( | ||
msg.head.path = msg.head.path.replace(r.rewrite[0], r.rewrite[1]) | ||
) | ||
|
||
))() | ||
) | ||
) | ||
.chain() | ||
|
||
)() |
53 changes: 53 additions & 0 deletions
53
packages/server/config/website/template/pjs/plugins/serve-files.js
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,53 @@ | ||
(( | ||
config = pipy.solve('config.js'), | ||
|
||
sites = config['serve-files'], | ||
|
||
mimeTypes = config['mime'].types, | ||
|
||
) => pipy({ | ||
_file: null, | ||
_reqPathName: null | ||
}) | ||
|
||
.import({ | ||
__route: 'main', | ||
}) | ||
|
||
.pipeline() | ||
.handleMessageStart( | ||
msg => ( | ||
(( | ||
root = sites[__route]?.root, | ||
) => ( | ||
_reqPathName = new URL(msg.head.path).pathname, | ||
root && ( | ||
_file = http.File.from(root + _reqPathName) | ||
) | ||
|
||
))() | ||
) | ||
) | ||
.branch( | ||
() => Boolean(_file), ( | ||
$ => $ | ||
.replaceData() | ||
.replaceMessage( | ||
msg => _file.toMessage(msg.head.headers['accept-encoding']) | ||
) | ||
.handleMessageStart( | ||
(msg, ext) => ( | ||
_reqPathName | ||
&& _reqPathName.indexOf(".") > -1 | ||
&& (ext = _reqPathName.split(".")[_reqPathName.split(".").length - 1]), | ||
ext | ||
&& mimeTypes[ext] | ||
&& (msg.head.headers["content-type"] = mimeTypes[ext]) | ||
) | ||
) | ||
), | ||
$ => $.chain() | ||
) | ||
|
||
|
||
)() |
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 @@ | ||
|
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 @@ | ||
|
Empty file.
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
Empty file.
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
Oops, something went wrong.