Commit c84b163946469ad4c34c95c5bb7496f68f48136b

Authored by sumatek
1 parent 6fc87409
Exists in master

update data structure

.idea/express-project.iml
... ... @@ -1,12 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<module type="WEB_MODULE" version="4">
3   - <component name="NewModuleRootManager">
4   - <content url="file://$MODULE_DIR$">
5   - <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6   - <excludeFolder url="file://$MODULE_DIR$/temp" />
7   - <excludeFolder url="file://$MODULE_DIR$/tmp" />
8   - </content>
9   - <orderEntry type="inheritedJdk" />
10   - <orderEntry type="sourceFolder" forTests="false" />
11   - </component>
12   -</module>
13 0 \ No newline at end of file
.idea/jsLibraryMappings.xml
... ... @@ -1,6 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project version="4">
3   - <component name="JavaScriptLibraryMappings">
4   - <includedPredefinedLibrary name="Node.js Core" />
5   - </component>
6   -</project>
7 0 \ No newline at end of file
.idea/markdown-navigator.xml
... ... @@ -1,72 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project version="4">
3   - <component name="MarkdownProjectSettings">
4   - <PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true">
5   - <PanelProvider>
6   - <provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
7   - </PanelProvider>
8   - </PreviewSettings>
9   - <ParserSettings gitHubSyntaxChange="false">
10   - <PegdownExtensions>
11   - <option name="ABBREVIATIONS" value="false" />
12   - <option name="ANCHORLINKS" value="true" />
13   - <option name="ASIDE" value="false" />
14   - <option name="ATXHEADERSPACE" value="true" />
15   - <option name="AUTOLINKS" value="true" />
16   - <option name="DEFINITIONS" value="false" />
17   - <option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
18   - <option name="FENCED_CODE_BLOCKS" value="true" />
19   - <option name="FOOTNOTES" value="false" />
20   - <option name="HARDWRAPS" value="false" />
21   - <option name="HTML_DEEP_PARSER" value="false" />
22   - <option name="INSERTED" value="false" />
23   - <option name="QUOTES" value="false" />
24   - <option name="RELAXEDHRULES" value="true" />
25   - <option name="SMARTS" value="false" />
26   - <option name="STRIKETHROUGH" value="true" />
27   - <option name="SUBSCRIPT" value="false" />
28   - <option name="SUPERSCRIPT" value="false" />
29   - <option name="SUPPRESS_HTML_BLOCKS" value="false" />
30   - <option name="SUPPRESS_INLINE_HTML" value="false" />
31   - <option name="TABLES" value="true" />
32   - <option name="TASKLISTITEMS" value="true" />
33   - <option name="TOC" value="false" />
34   - <option name="WIKILINKS" value="true" />
35   - </PegdownExtensions>
36   - <ParserOptions>
37   - <option name="COMMONMARK_LISTS" value="true" />
38   - <option name="DUMMY" value="false" />
39   - <option name="EMOJI_SHORTCUTS" value="true" />
40   - <option name="FLEXMARK_FRONT_MATTER" value="false" />
41   - <option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
42   - <option name="GFM_TABLE_RENDERING" value="true" />
43   - <option name="GITBOOK_URL_ENCODING" value="false" />
44   - <option name="GITHUB_EMOJI_URL" value="false" />
45   - <option name="GITHUB_LISTS" value="false" />
46   - <option name="GITHUB_WIKI_LINKS" value="true" />
47   - <option name="JEKYLL_FRONT_MATTER" value="false" />
48   - <option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
49   - </ParserOptions>
50   - </ParserSettings>
51   - <HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true">
52   - <GeneratorProvider>
53   - <provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
54   - </GeneratorProvider>
55   - <headerTop />
56   - <headerBottom />
57   - <bodyTop />
58   - <bodyBottom />
59   - </HtmlSettings>
60   - <CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssTextEnabled="false" isDynamicPageWidth="true">
61   - <StylesheetProvider>
62   - <provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
63   - </StylesheetProvider>
64   - <ScriptProviders />
65   - <cssText />
66   - </CssSettings>
67   - <HtmlExportSettings updateOnSave="false" parentDir="$ProjectFileDir$" targetDir="$ProjectFileDir$" cssDir="" scriptDir="" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetExt="" useTargetExt="false" noCssNoScripts="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" />
68   - <LinkMapSettings>
69   - <textMaps />
70   - </LinkMapSettings>
71   - </component>
72   -</project>
73 0 \ No newline at end of file
.idea/markdown-navigator/profiles_settings.xml
... ... @@ -1,3 +0,0 @@
1   -<component name="MarkdownNavigator.ProfileManager">
2   - <settings default="" pdf-export="" />
3   -</component>
4 0 \ No newline at end of file
.idea/misc.xml
... ... @@ -1,6 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project version="4">
3   - <component name="JavaScriptSettings">
4   - <option name="languageLevel" value="ES6" />
5   - </component>
6   -</project>
7 0 \ No newline at end of file
.idea/modules.xml
... ... @@ -1,8 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project version="4">
3   - <component name="ProjectModuleManager">
4   - <modules>
5   - <module fileurl="file://$PROJECT_DIR$/.idea/express-project.iml" filepath="$PROJECT_DIR$/.idea/express-project.iml" />
6   - </modules>
7   - </component>
8   -</project>
9 0 \ No newline at end of file
.idea/vcs.xml
... ... @@ -1,6 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project version="4">
3   - <component name="VcsDirectoryMappings">
4   - <mapping directory="$PROJECT_DIR$" vcs="Git" />
5   - </component>
6   -</project>
7 0 \ No newline at end of file
app.config.json
... ... @@ -49,6 +49,9 @@
49 49 },
50 50 "dev": {
51 51  
52   - }
  52 + },
  53 + "gentest": {
  54 +
  55 + }
53 56 }
54 57  
... ...
app.js
1 1 require('app-module-path').addPath(__dirname);
2 2 const express = require('express');
3 3 const app = express();
4   -const utils = require('utils/utils');
5   -// const conf = require('utils/config');
6   -// var log = require('./utils/log');
7   -// var constants = require('./utils/constants');
8 4  
  5 +
  6 +//core
9 7 var core = require('./utils/core');
10 8 // var stats = core.stats;
11 9 var log = core.log;
12 10 var constants = core.constants;
13 11 var conf = core.config;
14 12 core.init(app);
15   -//init
16   -// app.use(function (req, res, next) {
17   -// core.init(app);
18   -// next();
19   -// });
  13 +
  14 +//helper
  15 +const utils = require('utils/utils');
  16 +
  17 +
  18 +//setup help build message resBody
  19 +function logResponseBody(req, res, next) {
  20 + var oldWrite = res.write,
  21 + oldEnd = res.end;
  22 +
  23 + var chunks = [];
  24 +
  25 + res.write = function (chunk) {
  26 + chunks.push(chunk);
  27 + oldWrite.apply(res, arguments);
  28 + };
  29 +
  30 + res.end = function (chunk) {
  31 + var body = '';
  32 +
  33 + if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
  34 + res["resBody"] = body ;
  35 + oldEnd.apply(res, arguments);
  36 + return ;
  37 + }
  38 +
  39 + if (!(chunk instanceof String || typeof chunk === 'string' ) )
  40 + chunks.push(chunk);
  41 + try {
  42 + //console.dir(chunks);
  43 + body = chunks.length > 0? Buffer.concat(chunks).toString('utf8') :'';
  44 + } catch (error) {
  45 + logger.errorStack(error);
  46 + }
  47 +
  48 + res["resBody"] = body ;
  49 +
  50 + oldEnd.apply(res, arguments);
  51 + };
  52 +
  53 + next();
  54 +}
  55 +app.use(logResponseBody);
  56 +
  57 +// setup json body parser
  58 +const bodyParser = require('body-parser');
  59 +app.use(bodyParser.json());
  60 +
  61 +// Enable CORS
  62 +app.use(function (req, res, next) {
  63 + // add generated request-id to session
  64 + //req.session.reqId = req.id;
  65 + // Enable CORS
  66 + // res.header("Access-Control-Allow-Origin", "*");
  67 + res.header("Access-Control-Allow-Credentials", "true");
  68 + res.header("Access-Control-Allow-Origin", req.headers.origin);
  69 + res.header("Access-Control-Allow-Methods", "POST, PUT, GET, DELETE, OPTIONS");
  70 + res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  71 + next();
  72 +});
  73 +
20 74  
21 75 // console.log(conf.get('redis.host'));
22 76  
... ... @@ -24,8 +78,6 @@ core.init(app);
24 78 const addRequestId = require('express-request-id')();
25 79 app.use(addRequestId);
26 80  
27   -
28   -
29 81 // setup express-session with redis store
30 82 const session = require('express-session');
31 83 // const RedisStore = require('connect-redis')(session);
... ... @@ -46,51 +98,6 @@ const uuidV4 = require(&#39;uuid/v4&#39;);
46 98 // cookie: { maxAge: 3600000 }
47 99 // }));
48 100  
49   -
50   -
51   -function logResponseBody(req, res, next) {
52   - var oldWrite = res.write,
53   - oldEnd = res.end;
54   -
55   - var chunks = [];
56   -
57   - res.write = function (chunk) {
58   - chunks.push(chunk);
59   - oldWrite.apply(res, arguments);
60   - };
61   -
62   - res.end = function (chunk) {
63   - var body = '';
64   -
65   - if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
66   - res["resBody"] = body ;
67   - oldEnd.apply(res, arguments);
68   - return ;
69   - }
70   -
71   - if (!(chunk instanceof String || typeof chunk === 'string' ) )
72   - chunks.push(chunk);
73   - try {
74   - //console.dir(chunks);
75   - body = chunks.length > 0? Buffer.concat(chunks).toString('utf8') :'';
76   - } catch (error) {
77   - logger.errorStack(error);
78   - }
79   -
80   - res["resBody"] = body ;
81   -
82   - oldEnd.apply(res, arguments);
83   - };
84   -
85   - next();
86   - }
87   -
88   -app.use(logResponseBody);
89   -
90   -// setup json body parser
91   -const bodyParser = require('body-parser');
92   -app.use(bodyParser.json());
93   -
94 101 // setup logger
95 102 // const logger = require('utils/request-logger');
96 103  
... ... @@ -131,20 +138,8 @@ app.use(bodyParser.json());
131 138  
132 139  
133 140  
134   -// var logg = require('./utils/cores/commonlog').init(conf.get("configlog"),app);
135   -app.use(function (req, res, next) {
136   - // add generated request-id to session
137   - //req.session.reqId = req.id;
138   - // Enable CORS
139   - // res.header("Access-Control-Allow-Origin", "*");
140   - res.header("Access-Control-Allow-Credentials", "true");
141   - res.header("Access-Control-Allow-Origin", req.headers.origin);
142   - res.header("Access-Control-Allow-Methods", "POST, PUT, GET, DELETE, OPTIONS");
143   - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
144   - next();
145   -});
146   -
147 141  
  142 +//check header
148 143 app.use(function( req, res, next ) {
149 144 if(req.headers["x-user"] && req.headers["usertoken"])
150 145 next();
... ... @@ -153,27 +148,20 @@ app.use(function( req, res, next ) {
153 148  
154 149 });
155 150  
  151 +//prepare incomming
156 152 app.use( function( req, res, next ) {
157 153 log.startEC(req);
158 154 req = utils.findQueryString(req);
159 155 next();
160 156 });
161 157  
162   -
163   -
164   -
165   -
166   -
167   -
168   -
169   -
170 158 // get BE api configs
171 159 const apiUrlPrefix = conf.get('apiUrlPrefix');
172 160  
173   -
174 161 let preference = require('./controllers/preference/index');
175 162 app.use(apiUrlPrefix+'/preference', preference);
176 163  
  164 +//prepare outgoing
177 165 app.use( function( req, res, next ) {
178 166 if(req.res.resBody)
179 167 {
... ...
utils/core.js
... ... @@ -3,9 +3,11 @@ var stats = require(&#39;./cores/stats&#39;);
3 3 var constants = require('./cores/constants')
4 4 var config = require('./cores/config')
5 5  
  6 +var logg = require('./cores/commonlog');
  7 +
6 8 var init = function(app)
7 9 {
8   - require('./cores/commonlog').init(config.get("configlog"),app);
  10 + logg.init(config.get("configlog"),app);
9 11 }
10 12  
11 13  
... ...