URL Parameters not working on NodeJS deployment with CPanel

梦想与她 提交于 2021-01-29 10:18:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!