Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mock server for localhost. #237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions source/control-panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
15 changes: 15 additions & 0 deletions source/control-panel/mocks/cors.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
22 changes: 22 additions & 0 deletions source/control-panel/mocks/data.json
Original file line number Diff line number Diff line change
@@ -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"]
}
7 changes: 7 additions & 0 deletions source/control-panel/mocks/routes.json
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 10 additions & 1 deletion source/control-panel/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
},
};