diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8606125 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${file}" + } + ] +} diff --git a/chapter04/src/restful_regions.js b/chapter04/src/restful_regions.js index a17f4d9..0ef8eb9 100644 --- a/chapter04/src/restful_regions.js +++ b/chapter04/src/restful_regions.js @@ -48,6 +48,8 @@ const getRegion = async ( `; } + res.set("Connection", "close"); + const regions = await dbConn.query(sqlQuery); if (regions.length > 0 || region === null) { res @@ -69,6 +71,8 @@ const deleteRegion = async ( region: string ) => { try { + res.set("Connection", "close"); + const sqlCities = ` SELECT 1 FROM cities WHERE countryCode="${country}" @@ -103,6 +107,8 @@ const postRegion = async ( country: string, name: string ) => { + res.set("Connection", "close"); + if (!name) { return res.status(400).send("Missing name"); } @@ -155,6 +161,8 @@ const putRegion = async ( region: string, name: string ) => { + res.set("Connection", "close"); + if (!name) { return res.status(400).send("Missing name"); } diff --git a/chapter04/src/restful_server.js b/chapter04/src/restful_server.js index 6186f95..df845a5 100644 --- a/chapter04/src/restful_server.js +++ b/chapter04/src/restful_server.js @@ -32,11 +32,8 @@ const { app.get("/regions/", (req, res) => getRegion(res, dbConn)); -app.get( - "/regions/:country/", - (req, res) => ( - console.log(req), getRegion(res, dbConn, req.params.country) - ) +app.get("/regions/:country/", (req, res) => + getRegion(res, dbConn, req.params.country) ); app.get("/regions/:country/:region/", (req, res) =>