Pārlūkot izejas kodu

设置本地数据库开发

zengyicheng 2 gadi atpakaļ
vecāks
revīzija
bfbabb07a6
3 mainītis faili ar 24 papildinājumiem un 24 dzēšanām
  1. 17 17
      app.js
  2. 2 2
      mysql.js
  3. 5 5
      ssti.js

+ 17 - 17
app.js

@@ -1,12 +1,12 @@
 // call the packages we need
-var express = require('express');        // call express
-var app = express();                 // define our app using express
+var express = require('express'); // call express
+var app = express(); // define our app using express
 var bodyParser = require('body-parser');
 var request = require("request");
-const edurouter = require('./pbl');
+const edurouter = require('./ssti');
 const morgan = require('morgan');
 var path = require("path");
-var port = "7003";        // set our port
+var port = "7003"; // set our port
 //const cors = require('cors')
 app.use(morgan('dev'));
 // configure app to use bodyParser()
@@ -15,7 +15,7 @@ app.use(bodyParser.urlencoded({ extended: true, limit: '3mb' }));
 app.use(bodyParser.json({ limit: '3mb' }));
 
 //暂时全跨域
-app.use(function (req, res, next) {
+app.use(function(req, res, next) {
     ///var allowedOrigins = [config.local.origin,'http://cocorobo.hk','http://www.cocorobo.hk','https://cocorobo.hk','http://cloud.cocorobo.hk','https://cloud.cocorobo.hk'];
     var origin = req.headers.origin || "*";
     //if(allowedOrigins.indexOf(origin) > -1){
@@ -26,7 +26,7 @@ app.use(function (req, res, next) {
     res.header('Access-Control-Allow-Credentials', true);
     //修改程序信息与版本
     res.header('X-Powered-By', ' 3.2.1')
-    //内容类型:如果是post请求必须指定这个属性
+        //内容类型:如果是post请求必须指定这个属性
     res.header('Content-Type', 'application/json;charset=utf-8')
     next();
 });
@@ -39,20 +39,20 @@ app.use(cors({
 }));
 */
 // all of our routes will be prefixed with /api
-app.use('/api/pbl', edurouter);
+app.use('/api', edurouter);
 // app.use('/game', game);
 
-app.all('/download', function (req, res, next) {
+app.all('/download', function(req, res, next) {
     //req.body.url = "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/%E4%B8%8B%E8%BD%BD%20%284%29.doc";
     request({
-        url: req.body.url,
-        method: "GET",
-        encoding: null,
-        headers: {
-            'Accept-Encoding': 'gzip, deflate'
-        }
-    },
-        function (error, response, body) {
+            url: req.body.url,
+            method: "GET",
+            encoding: null,
+            headers: {
+                'Accept-Encoding': 'gzip, deflate'
+            }
+        },
+        function(error, response, body) {
             if (!error && response.statusCode == 200) {
                 res.setHeader('Content-Type', 'application/force-download');
                 res.setHeader('Content-Disposition', 'attachment; filename=' + path.basename(req.body.url));
@@ -65,4 +65,4 @@ app.all('/download', function (req, res, next) {
 // START THE SERVER
 // =============================================================================
 app.listen(port);
-console.log('app happens on port ' + port);
+console.log('app happens on port ' + port);

+ 2 - 2
mysql.js

@@ -11,8 +11,8 @@ us.mysqlconnection = function(host, database) {
         us.sqle[host][database] = us.mysql.createPool({
             connectionLimit: 0,
             host: host, //数据库地址
-            // user: "root", //用户名
-            // password: "cocorobo", //密码
+            user: "root", //用户名
+            password: "222333888", //密码
             database: database, //数据库名称
             // port: 20007 //端口
         }); //连接超时和错误从连

+ 5 - 5
pbl.js → ssti.js

@@ -5,7 +5,7 @@ var bcrypt = require('bcryptjs');
 var router = express.Router(); // get an instance of the express Router
 const querystring = require('querystring');
 var mysql = require('./mysql');
-// const _mysqlLabor = ["123.58.32.151", "pbl"]; //双创數據庫信息
+const _mysqlLabor = ["10.3.16.226", "ssti_cm"]; //本地双创數據庫信息
 // const _mysqlLabor = ["172.16.12.5", "pbl"]; //双创數據庫信息
 var crypto = require('crypto');
 var https = require('https');
@@ -30,11 +30,11 @@ function asynnext(req, res, next) {
 /*測試*/
 router.route('/a').all((req, res, next) => {
     var json = queryString(req.url);
-    getmysql(req, res, "a", json['ph'], json['pa']);
-});
-router.route('/b').all((req, res, next) => {
-    postmysql(req, res, "b");
+    getmysql(req, res, "a");
 });
+// router.route('/b').all((req, res, next) => {
+//     postmysql(req, res, "b");
+// });
 
 queryString = function(url) {
     var a = url.split("?");