我真的很陌生,我试图了解发送静态文件是如何工作的。我设法为我的索引文件提供服务,但是我无法将其他文件作为GET请求的响应。Node/Express根据请求发送静态文件
app.use(express.static(path.join(__dirname, '/client/build')))
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, '.', 'client/build/', 'index.html'))
res.end()
})
app.get('/portfolio', (req, res) => {
const person = req.query.name
var filePath = __dirname + '/client/build/' + person + '/' + 'index.html'
res.sendFile(filePath)
res.end()
})
我发现了类似的问题,但似乎没有任何工作。
我发送请求为:
fetch(`portfolio?name=${who}`)
你发送给服务器的请求是什么? – alexmac
什么是“人”,你发送给服务器的请求是什么? @alexmac – turmuka
我编辑的问题,请求 取('组合?name = $ {}谁') 其中“谁”是投资组合持有 – Braian