Browse Source

Fix : cors middleware - #12

pull/13/head
oof1lab 7 years ago
parent
commit
1054fc529b
  1. 2
      bin/index.js
  2. 2
      index.js
  3. 2
      lib/xctrl.js
  4. 2
      lib/xsql.js
  5. 18
      package-lock.json
  6. 1
      package.json

2
bin/index.js

@ -5,6 +5,7 @@ const bodyParser = require('body-parser');
const express = require('express'); const express = require('express');
const sqlConfig = require('commander'); const sqlConfig = require('commander');
const mysql = require('mysql'); const mysql = require('mysql');
const cors = require('cors');
const dataHelp = require('../lib/util/data.helper.js'); const dataHelp = require('../lib/util/data.helper.js');
const Xapi = require('../lib/xapi.js'); const Xapi = require('../lib/xapi.js');
const cmdargs = require('../lib/util/cmd.helper.js'); const cmdargs = require('../lib/util/cmd.helper.js');
@ -16,6 +17,7 @@ cmdargs.handle(sqlConfig)
/**************** START : setup express ****************/ /**************** START : setup express ****************/
let app = express(); let app = express();
app.use(morgan('tiny')) app.use(morgan('tiny'))
app.use(cors())
app.use(bodyParser.json()) app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ app.use(bodyParser.urlencoded({
extended: true extended: true

2
index.js

@ -5,6 +5,7 @@ const bodyParser = require('body-parser');
const express = require('express'); const express = require('express');
const sqlConfig = require('commander'); const sqlConfig = require('commander');
const mysql = require('mysql'); const mysql = require('mysql');
const cors = require('cors');
const dataHelp = require('./lib/util/data.helper.js'); const dataHelp = require('./lib/util/data.helper.js');
const Xapi = require('./lib/xapi.js'); const Xapi = require('./lib/xapi.js');
@ -17,6 +18,7 @@ cmdargs.handle(sqlConfig)
/**************** START : setup express ****************/ /**************** START : setup express ****************/
let app = express(); let app = express();
app.use(morgan('tiny')) app.use(morgan('tiny'))
app.use(cors())
app.use(bodyParser.json()) app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ app.use(bodyParser.urlencoded({
extended: true extended: true

2
lib/xctrl.js

@ -197,7 +197,7 @@ class xctrl {
//console.log(req.app.locals._tableName, req.body); //console.log(req.app.locals._tableName, req.body);
this.mysql.getBulkInsertStatement(req.app.locals._tableName, req.body, queryParamsObj) this.mysql.prepareBulkInsert(req.app.locals._tableName, req.body, queryParamsObj)
results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params); results = await this.mysql.exec(queryParamsObj.query, queryParamsObj.params);
res.status(200).json(results); res.status(200).json(results);

2
lib/xsql.js

@ -206,7 +206,7 @@ class Xsql {
} }
getBulkInsertStatement(tableName, objectArray, queryParamsObj) { prepareBulkInsert(tableName, objectArray, queryParamsObj) {
if (tableName in this.metaDb.tables && objectArray) { if (tableName in this.metaDb.tables && objectArray) {

18
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "xmysql", "name": "xmysql",
"version": "0.1.9", "version": "0.4.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -194,6 +194,22 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
}, },
"cors": {
"version": "2.8.4",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz",
"integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=",
"requires": {
"object-assign": "4.1.1",
"vary": "1.1.2"
},
"dependencies": {
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
}
}
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",

1
package.json

@ -28,6 +28,7 @@
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"colors": "^1.1.2", "colors": "^1.1.2",
"commander": "^2.11.0", "commander": "^2.11.0",
"cors": "^2.8.4",
"express": "^4.16.1", "express": "^4.16.1",
"mocha": "^4.0.1", "mocha": "^4.0.1",
"morgan": "^1.9.0", "morgan": "^1.9.0",

Loading…
Cancel
Save