Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from ParadoxalCorp/indev
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
ParadoxOrigins authored Aug 20, 2018
2 parents 4e1389c + 4815788 commit e4ac363
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .circleci/config.yml
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

27 changes: 27 additions & 0 deletions .eslintrc.json
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"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ typings/

# next.js build output
.next

test\.js
config\.js
package-lock\.json
6 changes: 5 additions & 1 deletion README.md
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
6 changes: 6 additions & 0 deletions config.example.js
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'
};
51 changes: 51 additions & 0 deletions index.js
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}`);
})();
29 changes: 29 additions & 0 deletions package.json
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"
}
}

0 comments on commit e4ac363

Please sign in to comment.