当我在终端中使用此Curl命令时:
curl -X POST -H "Content-Type: application/json" localhost:8080/api/v1/quote/car-insurance --data '{"car_value": 20000.0, "driver_birthdate": "15/10/1990"}'
我在终端中收到以下错误消息:
Curl: failed to connect to localhost port 8080: Connection refused
有人可以向我解释为什么拒绝连接吗?
app.js
const express = require("express")
const bodyParser = require("body-parser")
const insuranceQuoteRoutes = require("./routes/insuranceQuotes")
const app = express()
app.use(bodyParser.json())
app.use("/api", insuranceQuoteRoutes)
app.listen(8080)
module.exports = app
insuranceQuotes.js
const express = require("express")
const {body, validationResult} = require("express-validator");
const insuranceQuoteController = require("../controllers/insuranceQuotesControllers")
const router = express.Router()
//carDateRegex: https://www.regextester.com/99555
const carDateRegex = /^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}$/
//Express-validator: https://express-validator.github.io/docs/
router.post("/v1/quote/car-insurance", [
body("car_value").isFloat(),
body("driver_birthdate").matches(carDateRegex)
], insuranceQuoteController.postInsuranceQuotes);
module.exports = router