Skip to content

Commit 6b87d6a

Browse files
committed
initial commit
0 parents  commit 6b87d6a

File tree

66 files changed

+14066
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+14066
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
yarn-error.log
34+
testem.log
35+
/typings
36+
37+
# System Files
38+
.DS_Store
39+
Thumbs.db

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Redis manager
2+
3+
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.1.4.
4+
5+
### Dependencies
6+
7+
- Node 8.11.x , npm 5.6.x
8+
- redis 4.x
9+
10+
### Redis
11+
12+
- follow here https://redis.io/download download and compile redis server or follow this commands
13+
14+
```
15+
$ wget http://download.redis.io/releases/redis-4.0.11.tar.gz
16+
$ tar xzf redis-4.0.11.tar.gz
17+
$ cd redis-4.0.11
18+
$ make
19+
```
20+
21+
- start up redis server `cd src` `./redis-server`
22+
- load sample data into redis server, `cd src`, then run this `cat <submission-folder>/simple-data-txt.txt | ./redis-cli --pipe` import simple data.
23+
24+
### Local run
25+
26+
- goto submission folder, run `npm i` first
27+
- just run `npm run start`, and use browers open http://127.0.0.1:3003
28+
29+
### Configs
30+
31+
| Key | default | Description |
32+
| ---------------------------------------- | ---------------- | -------------------------------- |
33+
| config/default.js **PORT** | 3003 | the web app run port |
34+
| config/default.js **API_VERSION** | api/1.0 | the backend endpoint prefix |
35+
| config/default.js **LOG_LEVEL** | Debug | the backend log level |
36+
| src/environments/environments.ts **URI** | /backend/api/1.0 | the backend uri used in frontend |
37+
38+
39+
40+
### Additional document
41+
42+
- Frontend
43+
44+
- Angular 6
45+
- Angular Material https://material.angular.io/
46+
- Material Icons https://material.io/tools/icons/?style=baseline
47+
48+
- Backend
49+
50+
- express
51+
- ioredis https://github.com/luin/ioredis
52+
53+
- Commands
54+
55+
- what commands are included ?
56+
57+
INFO,GET,SET,RPUSH,SADD,ZADD,HMSET,LRANGE,ZRANGE,SMEMBERS,HGETALL,LLEN, SCARD, ZCARD,HLEN
58+
59+
- what commands should be added next?
60+
61+
- SREM remove one element from set
62+
- ZREM remove one element from ordered set
63+
- HSET, HMSET, HDEL, update/delete single/values from hash map
64+
- Other commands may need accroding to functions.
65+
66+
- which commands are dependent on one another?
67+
68+
a web app function dependent a lot of command, so, in fact, there is no command dependent on one another command.

angular.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"redis-manager": {
7+
"root": "",
8+
"sourceRoot": "src",
9+
"projectType": "application",
10+
"prefix": "app",
11+
"schematics": {
12+
"@schematics/angular:component": {
13+
"styleext": "scss"
14+
}
15+
},
16+
"architect": {
17+
"build": {
18+
"builder": "@angular-devkit/build-angular:browser",
19+
"options": {
20+
"outputPath": "dist",
21+
"index": "src/index.html",
22+
"main": "src/main.ts",
23+
"polyfills": "src/polyfills.ts",
24+
"tsConfig": "src/tsconfig.app.json",
25+
"assets": [
26+
"src/favicon.ico",
27+
"src/assets"
28+
],
29+
"styles": [
30+
"src/styles.scss"
31+
],
32+
"scripts": []
33+
},
34+
"configurations": {
35+
"production": {
36+
"fileReplacements": [
37+
{
38+
"replace": "src/environments/environment.ts",
39+
"with": "src/environments/environment.prod.ts"
40+
}
41+
],
42+
"optimization": true,
43+
"outputHashing": "all",
44+
"sourceMap": false,
45+
"extractCss": true,
46+
"namedChunks": false,
47+
"aot": true,
48+
"extractLicenses": true,
49+
"vendorChunk": false,
50+
"buildOptimizer": true
51+
}
52+
}
53+
},
54+
"serve": {
55+
"builder": "@angular-devkit/build-angular:dev-server",
56+
"options": {
57+
"browserTarget": "redis-manager:build"
58+
},
59+
"configurations": {
60+
"production": {
61+
"browserTarget": "redis-manager:build:production"
62+
}
63+
}
64+
},
65+
"extract-i18n": {
66+
"builder": "@angular-devkit/build-angular:extract-i18n",
67+
"options": {
68+
"browserTarget": "redis-manager:build"
69+
}
70+
},
71+
"test": {
72+
"builder": "@angular-devkit/build-angular:karma",
73+
"options": {
74+
"main": "src/test.ts",
75+
"polyfills": "src/polyfills.ts",
76+
"tsConfig": "src/tsconfig.spec.json",
77+
"karmaConfig": "src/karma.conf.js",
78+
"styles": [
79+
"src/styles.scss"
80+
],
81+
"scripts": [],
82+
"assets": [
83+
"src/favicon.ico",
84+
"src/assets"
85+
]
86+
}
87+
},
88+
"lint": {
89+
"builder": "@angular-devkit/build-angular:tslint",
90+
"options": {
91+
"tsConfig": [
92+
"src/tsconfig.app.json",
93+
"src/tsconfig.spec.json"
94+
],
95+
"exclude": [
96+
"**/node_modules/**"
97+
]
98+
}
99+
}
100+
}
101+
}
102+
},
103+
"defaultProject": "redis-manager"
104+
}

app.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright (C) 2017 TopCoder Inc., All Rights Reserved.
3+
*/
4+
/**
5+
* The application entry point
6+
*
7+
* @author TCSCODER
8+
* @version 1.0
9+
*/
10+
11+
12+
13+
14+
const express = require('express');
15+
const cross = require('cors');
16+
const bodyParser = require('body-parser');
17+
const _ = require('lodash');
18+
const config = require('config');
19+
const http = require('http');
20+
const path = require('path');
21+
const logger = require('./lib/common/logger');
22+
const errorMiddleware = require('./lib/common/error.middleware');
23+
const routes = require('./lib/route');
24+
25+
const app = express();
26+
const httpServer = http.Server(app);
27+
28+
29+
app.set('port', config.PORT);
30+
app.use(bodyParser.json());
31+
app.use(bodyParser.urlencoded({extended: true}));
32+
app.use(cross());
33+
const apiRouter = express.Router({});
34+
35+
// load all routes
36+
_.each(routes, (verbs, url) => {
37+
_.each(verbs, (def, verb) => {
38+
let actions = [];
39+
40+
const {method} = def;
41+
if (!method) {
42+
throw new Error(`${verb.toUpperCase()} ${url} method is undefined`);
43+
}
44+
if (def.middleware && def.middleware.length > 0) {
45+
actions = actions.concat(def.middleware);
46+
}
47+
48+
actions.push(async (req, res, next) => {
49+
try {
50+
await method(req, res, next);
51+
} catch (e) {
52+
next(e);
53+
}
54+
});
55+
56+
const middlewares = [];
57+
for (let i = 0; i < actions.length - 1; i += 1) {
58+
if (actions[i].name.length !== 0) {
59+
middlewares.push(actions[i].name);
60+
}
61+
}
62+
63+
logger.info(`Endpoint discovered : [${middlewares.join(',')}] ${verb.toLocaleUpperCase()} /${config.API_VERSION}${url}`);
64+
apiRouter[verb](`/${config.API_VERSION}${url}`, actions);
65+
});
66+
});
67+
app.use('/backend/', apiRouter);
68+
app.use(errorMiddleware());
69+
70+
// Serve static assets
71+
app.use(express.static(path.resolve(__dirname, 'dist')));
72+
// Always return the main index.html
73+
app.get('/', (req, res) => {
74+
res.sendFile(path.resolve(__dirname, 'dist', 'index.html'));
75+
});
76+
77+
78+
(async () => {
79+
if (!module.parent) { // this code will never run in unit test mode
80+
httpServer.listen(app.get('port'), () => {
81+
logger.info(`Express server listening on port ${app.get('port')}`);
82+
});
83+
} else {
84+
module.exports = app;
85+
}
86+
})();

config/default.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (C) 2017 TopCoder Inc., All Rights Reserved.
3+
*/
4+
/**
5+
* the default config
6+
*
7+
* @author TCSCODER
8+
* @version 1.0
9+
*/
10+
11+
module.exports = {
12+
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
13+
PORT: process.env.PORT || 3003,
14+
API_VERSION: 'api/1.0',
15+
};

config/production.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) 2017 Topcoder Inc, All rights reserved.
3+
*/
4+
5+
6+
/**
7+
* The production configuration file.
8+
*
9+
* @author TCSCODER
10+
* @version 1.0
11+
*/
12+
13+
module.exports = {
14+
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
15+
};

lib/common/error.middleware.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (C) 2018 TopCoder Inc., All Rights Reserved.
3+
*/
4+
/* eslint-disable no-unused-vars */
5+
6+
/**
7+
* Common error handling middleware
8+
*
9+
* @author TCSCODER
10+
* @version 1.0
11+
*/
12+
const logger = require('./logger');
13+
14+
const DEFAULT_MESSAGE = 'Something is broken at API server-side.';
15+
16+
/**
17+
* The error middleware function
18+
*
19+
* @param {Object} err the error that is thrown in the application
20+
* @param {Object} req the express request instance
21+
* @param {Object} res the express response instance
22+
* @param {Function} next the next middleware in the chain
23+
*/
24+
function middleware(err, req, res, next) {
25+
logger.logFullError(err);
26+
27+
if (err.isJoi) {
28+
res.status(400).json({message: err.details[0].message});
29+
} else if (err.errors) {
30+
res.status(400).json({message: err.errors});
31+
} else {
32+
const status = err.status || 500;
33+
const message = err.message || DEFAULT_MESSAGE;
34+
res.status(status).json({message});
35+
}
36+
}
37+
38+
module.exports = () => middleware;

0 commit comments

Comments
 (0)