我的快递代码::
ar express = require('express')
, http = require('http')
, mysql = require('mysql'); // <---- HERE
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: "root",
database: 'test123'
});
connection.connect(); // <---- AND HERE
// all environments
app.set('port', process.env.PORT || 7005);
app.get('/',function(request,response){
connection.query('SELECT * FROM test456', function(err, rows, fields)
{
console.log('Connection result error '+err);
console.log('no of records is '+rows.length);
response.writeHead(200, { 'Content-Type': 'application/json'});
response.end(JSON.stringify(rows));
});
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
我使用以下 SQL 查询来创建对应的数据库
CREATE TABLE test456 ( _id INT(10), name VARCHAR(30), image VARCHAR(50));
.
INSERT INTO test456 ( _id,name,image ) VALUES ( 1,"nature","http://54.218.73.244:7005/image.jpg" );
然后
mysql> SELECT * FROM test456;
+------+--------+-------------------------------------+
| _id | name | image |
+------+--------+-------------------------------------+
| 1 | nature | http://54.218.73.244:7005/image.jpg |
+------+--------+-------------------------------------+
1 row in set (0.00 sec)
但是当我通过浏览器尝试输入网址时,我无法获取图像
http://54.218.73.244:7005/image.jpg
我得到输出为::
Cannot GET /image.jpg
注意::我检查了指定位置有图片,
我在哪里编码错了