致电http://localhost:5000/surveycreate/4可以使我重定向到 surveypage.html
但是调用http://localhost:5000/surveycreate无效,它将我的主index.js文件重定向到公用文件夹中,甚至不显示“常规获取”
为什么会这样?
路线中的surveypage.js
const path = require("path");
const router = express.Router();
router.use(express.static(path.join(__dirname,"../public")));
router.get('/:id',async (req,res) => {
console.log("get with id");
res.sendFile(path.join(__dirname,"../public/Surveypage.html"));
})
router.get('/',res) => {
console.log("regular get");
res.sendFile(path.join(__dirname,"../public/Surveypage.html"));
})
module.exports = router; ```
==============================================================================
index.js of node:
const surveyPage = require('./routes/surveypage')
const app = express();
app.use(express.json());
app.use('/surveypage',surveyPage)
app.use(express.static(path.join(__dirname,"/public")));
app.use(cors())
const PORT = process.env.PORT || 5000
app.listen(PORT,() => {
console.log(`Listenning on porst ${PORT }`);
})