我正在尝试使用存储在postgres中的路径将图像发送到前端(Vuejs),我正在使用express。 首先,我想知道将图像发送到前面是否正确。
app.js
const app = express();
var fs = require('fs');
var path = require('path');
const db = require('./queries');
var dir = path.join(__dirname, '../assets');
console.log("DIR", dir);
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(cors())
app.get('/test', (req, res) => {
res.send({
message: `Hello you get that`
})
})
app.get('/games', db.getGames)
app.listen(process.env.PORT || 8081)
queries.js
const Pool = require('pg').Pool
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'TTTT',
password: 'XXXX!',
port: 5432,
})
const getGames = (request, response) => {
pool.query('SELECT * FROM games ORDER BY name ASC', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
module.exports = {
getGames
}
数据库:
总而言之,我想使用“ img”中的路径将其提供给前端。 我希望我已经足够清楚了。 (对不起,我的英语)