Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gzzhanghao committed Dec 30, 2019
1 parent 9a97fb9 commit 7289c3c
Show file tree
Hide file tree
Showing 32 changed files with 1,256 additions and 498 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.js
Expand Up @@ -6,6 +6,10 @@ module.exports = {

parser: 'babel-eslint',

plugins: [
'import',
],

env: {
node: true,
es6: true,
Expand All @@ -15,5 +19,14 @@ module.exports = {
'no-console': 0,
'indent': [2, 2, { SwitchCase: 1 }],
'comma-dangle': [2, 'always-multiline'],
'import/order': [2, {
'alphabetize': { order: 'asc' },
'pathGroups': [
{
pattern: '@/**',
group: 'parent',
}
],
}],
},
}
1 change: 1 addition & 0 deletions babel.config.js
Expand Up @@ -5,5 +5,6 @@ module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
['babel-plugin-module-resolver', { root: ['./src'], alias: { '@': './src' } }],
],
}
40 changes: 2 additions & 38 deletions bin/index.js
@@ -1,44 +1,8 @@
#!/usr/bin/env node

const path = require('path')
const { red } = require('chalk')
const { log } = require('../lib/utils')
const { HTTPParser } = require('http-parser-js')

process.on('uncaughtException', error => {
log(red('Uncaught exception'), '\n', error.stack)
})

process.on('unhandledRejection', error => {
log(red('Unhandled rejection'), '\n', error.stack)
})

HTTPParser.encoding = 'utf-8'
process.binding('http_parser').HTTPParser = HTTPParser

const commander = require('commander')
const pkg = require('../package.json')

commander
.version(pkg.version)
.arguments('[entry]')
.option('-p, --port <port>', 'proxy server port', 8123)
.option('-u, --upstream <proxy>', 'upstream options', 'direct')
.option('-e, --encoding [encoding]', 'http parser encoding', 'utf-8')
.option('-k, --key <path>', 'ssl private key path', 'ssl/key.pem')
.option('-c, --cert <path>', 'ssl certificate path', 'ssl/cert.pem')
.action((entry, args) => {
const { createServer } = require('..')

HTTPParser.encoding = args.encoding

const server = createServer({
cert: path.resolve(args.cert),
key: path.resolve(args.key),
entry: path.resolve(entry || 'lib'),
upstream: args.upstream,
})

server.listen(parseInt(args.port))
})

commander.parse(process.argv)
require('../lib/cli')
11 changes: 11 additions & 0 deletions jsconfig.json
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": [
"src/**/*"
]
}
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,9 @@
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"babel-eslint": "^10.0.1",
"eslint": "^5.9.0"
"babel-plugin-module-resolver": "^4.0.0",
"eslint": "^5.9.0",
"eslint-plugin-import": "^2.19.1"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 7289c3c

Please sign in to comment.