我是一个初学者,正在尝试理解node/express如何发送静态文件。我成功地服务了我的index文件,但我无法将其他文件作为GET请求的响应进行服务。
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}`)
fetch(`portfolio?name=${who}`)
这里的'who'是投资组合所有者的姓名(字符串)。 - Braian