From 6b22627bfa3306e69c18dbb1d3acf5455c7c6b9b Mon Sep 17 00:00:00 2001 From: kght6123 Date: Sun, 25 Dec 2022 22:20:06 +0900 Subject: [PATCH] add mock server for localhost. --- source/control-panel/README.md | 11 +++++++++++ source/control-panel/mocks/cors.js | 15 +++++++++++++++ source/control-panel/mocks/data.json | 22 ++++++++++++++++++++++ source/control-panel/mocks/routes.json | 7 +++++++ source/control-panel/vue.config.js | 11 ++++++++++- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 source/control-panel/mocks/cors.js create mode 100644 source/control-panel/mocks/data.json create mode 100644 source/control-panel/mocks/routes.json diff --git a/source/control-panel/README.md b/source/control-panel/README.md index 1088d9c..5fb87aa 100644 --- a/source/control-panel/README.md +++ b/source/control-panel/README.md @@ -20,5 +20,16 @@ npm run build npm run lint ``` +### Mock server for localhost +``` +npx json-server --watch mocks/data.json --routes mocks/routes.json --port 5000 --middlewares mocks/cors.js +``` + +- Public API URL: http://localhost:8080/api +- Private API URL: http://localhost:8080/api +- Event ID: 1 + +Otherwise enter a dummy value. + ### Customize configuration See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/source/control-panel/mocks/cors.js b/source/control-panel/mocks/cors.js new file mode 100644 index 0000000..af71518 --- /dev/null +++ b/source/control-panel/mocks/cors.js @@ -0,0 +1,15 @@ +module.exports = (req, res, next) => { + res.header('Access-Control-Allow-Origin', 'http://localhost:8080'); + res.header('Access-Control-Allow-Credentials', 'true') + res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') + res.header( + 'Access-Control-Allow-Headers', + 'Content-Type, Authorization, access_token' + ) + // intercept OPTIONS method + if ('OPTIONS' === req.method) { + res.send(200) + } else { + next(); + } +} \ No newline at end of file diff --git a/source/control-panel/mocks/data.json b/source/control-panel/mocks/data.json new file mode 100644 index 0000000..da5ca19 --- /dev/null +++ b/source/control-panel/mocks/data.json @@ -0,0 +1,22 @@ +{ + "num_active_tokens_1": { + "active_tokens": 101 + }, + "waiting_num_1": { + "waiting_num": 11 + }, + "serving_num_1": { + "serving_counter": 201 + }, + "expired_tokens_1": ["abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", "123"], + "num_active_tokens_abc": { + "active_tokens": 102 + }, + "waiting_num_abc": { + "waiting_num": 12 + }, + "serving_num_abc": { + "serving_counter": 202 + }, + "expired_tokens_abc": ["abc","def"] +} \ No newline at end of file diff --git a/source/control-panel/mocks/routes.json b/source/control-panel/mocks/routes.json new file mode 100644 index 0000000..87886ae --- /dev/null +++ b/source/control-panel/mocks/routes.json @@ -0,0 +1,7 @@ +{ + "/api/*": "/$1", + "/num_active_tokens?event_id=:event_id": "/num_active_tokens_:event_id", + "/waiting_num?event_id=:event_id": "/waiting_num_:event_id", + "/serving_num?event_id=:event_id": "/serving_num_:event_id", + "/expired_tokens?event_id=:event_id": "/expired_tokens_:event_id" +} \ No newline at end of file diff --git a/source/control-panel/vue.config.js b/source/control-panel/vue.config.js index f990580..80eed46 100644 --- a/source/control-panel/vue.config.js +++ b/source/control-panel/vue.config.js @@ -6,5 +6,14 @@ module.exports = { publicPath: (process.env.NODE_ENV === 'production' ? '/control-panel/' : '/'), outputDir: 'dist/www/control-panel', - transpileDependencies: true + transpileDependencies: true, + devServer:{ + proxy:{ + '^/api':{ + target: 'http://localhost:5000', + ws: true, + secure: false + } + } + }, };