问题
My code has two api calls in question. The first api call is a GET request that uses a URL query, which works perfectly. The second api call is a GET request that uses a URL parameter. For some reason the URL query works just fine but the URL parameter method does not work.
const express = require('express')
const path = require('path')
const app = express()
// Server side api call - testing out url query at https://website.com/api?id=12334
app.get('/api/', (req, res) => {
var sessionID = req.query.id
return res.send(sessionID)
})
// Server side api call - testing out url params at https://website.com/ping/12334
app.get('/ping/:id', (req, res) => {
var id = req.params.id;
return res.send(id)
})
app.use(express.static(path.join(__dirname, 'build')))
// Client side app
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
})
app.listen(process.env.PORT)
This
app.get('/ping/:id', (req, res) => {
var id = req.params.id;
return res.send(id)
})
simply returns a white page, when it should also return 12334
on that white page when I access https://website.com/ping/12334
来源:https://stackoverflow.com/questions/61781330/url-parameters-not-working-on-nodejs-deployment-with-cpanel