不确定以下路线的原因:' / api / auth' ,' / api / auth / sudo' 是我在浏览器 localhost:5003 / api / auth 或 / api / auth / sudo
上点击端点时无法正常工作/index.js
const express = require('express')
const helmet = require('helmet')
const path = require('path')
const app = express()
const cookieParser = require('cookie-parser');
app.use(helmet())
app.use(cookieParser())
app.use(express.static(path.join(__dirname + '/client/build')))
require('./routes/authentication.js')(app)
require('./routes/product.js')(app)
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'))
});
const PORT = process.env.PORT || 5003
app.listen(PORT, () => {
console.log(`listening on port ${PORT} `)
})
/routes/authentication.js
module.exports = (app) => {
app.get('/api/auth', (req, res) => {
console.log('THIS ROUTE IS BEING HIT')
})
app.get('/api/auth/sudo', (req, res) => {
console.log('COOKIE IS SET')
})
app.get('/api/test', (req,res) => {
console.log("TESTING THIS ROUTE TO SEE IF WORKS")
})
}
只有/ api / test路由有效。
当路由移动到index.js时,它们都可以工作。