This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ParadoxalCorp/indev
Release 1.0.0
- Loading branch information
Showing
7 changed files
with
161 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:10 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/mongo:3.4.4 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: npm i --production | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: npm test | ||
- run: npm run eslint-check | ||
|
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,27 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"impliedStrict": true, | ||
"jsx": true | ||
} | ||
}, | ||
"env": { | ||
"node": true | ||
}, | ||
"globals": { | ||
"Map": true, | ||
"Promise": true | ||
}, | ||
"rules": { | ||
"eqeqeq": "warn", | ||
"semi": "warn", | ||
"curly": "warn", | ||
"no-empty": "warn", | ||
"valid-jsdoc": "warn", | ||
"no-extra-semi": "warn", | ||
"no-unused-vars": "warn", | ||
"no-undef": "error" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -59,3 +59,7 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
test\.js | ||
config\.js | ||
package-lock\.json |
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,5 @@ | ||
# Zuihou | ||
# Zuihou | ||
|
||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b2b18d1cf56d490ab4c74eed7b10d687)](https://www.codacy.com/app/ParadoxCorp/Zuihou?utm_source=github.com&utm_medium=referral&utm_content=ParadoxalCorp/Zuihou&utm_campaign=Badge_Grade) [![CircleCI](https://circleci.com/gh/ParadoxalCorp/Zuihou.svg?style=svg)](https://circleci.com/gh/ParadoxalCorp/Zuihou) | ||
|
||
Zuihou is Felix's proxy server, due to the fact that Zuihou is exposed to untrusted sources, minimal auth is setup |
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,6 @@ | ||
module.exports = { | ||
//The port on which the server should listen | ||
port: 8080, | ||
//The token, or password, that is needed to use the proxy | ||
authorization: 'memes' | ||
}; |
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,51 @@ | ||
'use strict'; | ||
|
||
process.on('uncaughtException', console.error); | ||
process.on('unhandledRejection', console.error); | ||
|
||
const axios = require('axios').default; | ||
const Hapi = require('hapi'); | ||
const config = require('./config'); | ||
|
||
const server = Hapi.server({ | ||
port: config.port | ||
}); | ||
|
||
(async() => { | ||
server.route({ | ||
method: '*', | ||
path: '/', | ||
handler: async function (request, h) { | ||
if (request.headers.authorization !== config.authorization) { | ||
return h.response('Forbidden').code(403).message('Forbidden'); | ||
} | ||
return await axios({ | ||
method: request.payload.method || 'GET', | ||
headers: request.payload.headers, | ||
data: request.payload.data, | ||
url: request.payload.url, | ||
params: request.payload.params, | ||
responseType: request.payload.responseType | ||
}) | ||
.then(res => { | ||
console.log(`${new Date().toUTCString()} (UTC) | ${request.payload.method ? request.payload.method.toUpperCase() : 'GET'} | ${res.status} | ${request.payload.url}`); | ||
return h.response(JSON.stringify({ | ||
status: res.status, | ||
statusText: res.statusText, | ||
data: request.payload.responseType === 'arraybuffer' ? { | ||
buffer: res.data.toString('base64') | ||
} : res.data | ||
})).code(200); | ||
}) | ||
.catch(err => { | ||
console.error(`${new Date().toUTCString()} (UTC) | ${request.payload.method ? request.payload.method.toUpperCase() : 'GET'} | ${err.response.status} | ${request.payload.url}`); | ||
return h.response(JSON.stringify({ | ||
status: err.response.status, | ||
data: err.response.data | ||
})).message('Upstream server error').code(500); | ||
}); | ||
} | ||
}); | ||
await server.start(); | ||
console.log(`Server started at: ${server.info.uri}`); | ||
})(); |
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,29 @@ | ||
{ | ||
"name": "zuihou", | ||
"version": "1.0.0", | ||
"description": "Zuihou, a proxy server for Felix", | ||
"main": "index.js", | ||
"author": "ParadoxOrigins", | ||
"contributors": [ | ||
{ | ||
"name": "Niputi" | ||
}, | ||
{ | ||
"name": "Otaku17" | ||
} | ||
], | ||
"repository": "github:ParadoxalCorp/Zuihou", | ||
"license": "GPL-3.0", | ||
"scripts": { | ||
"start": "node index.js", | ||
"eslint-check": "eslint ." | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"hapi": "^17.5.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^10.0.0", | ||
"eslint": "^5.0.0" | ||
} | ||
} |