Commit 0cd5e26e authored by rockyl's avatar rockyl

proxy

parent 97cbe806
...@@ -5,6 +5,7 @@ const jsonServer = require('./json-server'); ...@@ -5,6 +5,7 @@ const jsonServer = require('./json-server');
program program
.option('-h, --host [string]', 'server host', 'localhost') .option('-h, --host [string]', 'server host', 'localhost')
.option('-p, --port [number]', 'server port', 3000) .option('-p, --port [number]', 'server port', 3000)
.option('--proxy [string]', 'server proxy address')
.option('-f, --folder [string]', 'folder of json files', './') .option('-f, --folder [string]', 'folder of json files', './')
.option('-k, --key-file [string]', 'ssl key file') .option('-k, --key-file [string]', 'ssl key file')
.option('-c, --cert-file [string]', 'ssl cert file') .option('-c, --cert-file [string]', 'ssl cert file')
...@@ -16,6 +17,7 @@ async function execute() { ...@@ -16,6 +17,7 @@ async function execute() {
jsonServer.start({ jsonServer.start({
host: program.host, host: program.host,
port: program.port, port: program.port,
proxy: program.port,
folder: program.folder, folder: program.folder,
keyFile: program.keyFile, keyFile: program.keyFile,
certFile: program.certFile, certFile: program.certFile,
......
...@@ -31,7 +31,7 @@ function handler(request, response) { ...@@ -31,7 +31,7 @@ function handler(request, response) {
content = fs.readFileSync(targetFile, 'utf-8'); content = fs.readFileSync(targetFile, 'utf-8');
} else if (fs.existsSync(targetFile = filePath + '/index.js')) { } else if (fs.existsSync(targetFile = filePath + '/index.js')) {
try { try {
const jsonObject = require(targetFile); const jsonObject = require(targetFile)();
content = JSON.stringify(jsonObject); content = JSON.stringify(jsonObject);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
...@@ -60,7 +60,7 @@ function handler(request, response) { ...@@ -60,7 +60,7 @@ function handler(request, response) {
exports.start = function (options) { exports.start = function (options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const {port, host, folder, keyFile, certFile} = options; const {port, host, proxy, folder, keyFile, certFile} = options;
jsonPath = path.resolve(folder); jsonPath = path.resolve(folder);
if (fs.existsSync(jsonPath)) { if (fs.existsSync(jsonPath)) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment