{"pageProps":{"code":{"crud.ts":{"name":"crud.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.text());\n\napp.get('/apple', (req, res) => {\n  const name = req.query.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  }));\n});\n\n// same for .put and .delete\napp.post('/orange', (req, res) => {\n  const body = JSON.parse(req.body);\n  const name = body.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending orange!`,\n  }));\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/crud.ts","fileext":"ts"},"crud2.ts":{"name":"crud2.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.text());\n\napp.get('/apple/:name', (req, res) => {\n  const name = req.params.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  }));\n});\n\napp.post('/apple/:name', (req, res) => {\n  const name = req.params.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  }));\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/crud2.ts","fileext":"ts"},"crud_json.ts":{"name":"crud_json.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.json());\n\napp.get('/apple', (req, res) => {\n  const name = req.query.name;\n  res.json({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  });\n});\n\n// same for .put and .delete\napp.post('/orange', (req, res) => {\n  const name = req.body.name;\n  res.json({\n    msg: `Hi ${name}, thanks for sending orange!`,\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/crud_json.ts","fileext":"ts"},"error.ts":{"name":"error.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.text());\n\napp.get('/apple/:name', (req, res) => {\n  const name = req.params.name;\n  if (name === 'Hayden') {\n    res.status(400).json({\n      error: 'Bad name',\n    });\n  } else {\n    res.json({\n      msg: `Hi ${name}, thanks for sending apple!`,\n    });\n  }\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/error.ts","fileext":"ts"},"express_basic.ts":{"name":"express_basic.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.text());\n\napp.get('/hello', (req, res) => {\n  res.send('Hello!');\n});\n\napp.get('/whats/up', (req, res) => {\n  res.send(JSON.stringify({\n    value: 'not much',\n  }));\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/express_basic.ts","fileext":"ts"},"express_json.ts":{"name":"express_json.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.json());\n\napp.get('/whats/up', (req, res) => {\n  res.json({\n    value: 'not much',\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/express_json.ts","fileext":"ts"},"input_params.ts":{"name":"input_params.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.json());\n\napp.get('/my/url/:name', (req, res) => {\n  const name = req.params.name;\n  res.json({\n    name: `Name is ${name}`,\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/input_params.ts","fileext":"ts"},"input_query.ts":{"name":"input_query.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.json());\n\napp.get('/my/url', (req, res) => {\n  const name = req.query.name;\n  const age = req.query.age;\n  res.json({\n    name: `Name is ${name}`,\n    age: `Age is ${age}`,\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/input_query.ts","fileext":"ts"},"jest.config.js":{"name":"jest.config.js","content":"module.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  maxWorkers: 1,\n};\n","path":"code/1531/24T1/4.2/jest.config.js","fileext":"js"},"package.json":{"name":"package.json","content":"{\n  \"name\": \"env2\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"jest src\",\n    \"tsc\": \"tsc --noImplicitAny\",\n    \"lint\": \"eslint src/**.ts\",\n    \"lint-fix\": \"eslint --fix src/**.ts\",\n    \"ts-node\": \"ts-node\",\n    \"jest\": \"jest\",\n    \"nodemon\": \"nodemon\",\n    \"ts-node-coverage\": \"nyc --reporter=text --reporter=lcov ts-node\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"@types/express\": \"^4.17.13\",\n    \"@types/http-errors\": \"^1.8.2\",\n    \"@types/jest\": \"^27.5.0\",\n    \"@types/node\": \"^17.0.27\",\n    \"@types/prompt-sync\": \"^4.1.1\",\n    \"@typescript-eslint/eslint-plugin\": \"^5.21.0\",\n    \"@typescript-eslint/parser\": \"^5.21.0\",\n    \"eslint\": \"^8.14.0\",\n    \"eslint-plugin-jest\": \"^26.1.5\",\n    \"jest\": \"^28.1.0\",\n    \"middleware-http-errors\": \"^0.1.0\",\n    \"nodemon\": \"^2.0.16\",\n    \"nyc\": \"^15.1.0\",\n    \"ts-jest\": \"^28.0.2\",\n    \"typescript\": \"^4.6.3\"\n  },\n  \"dependencies\": {\n    \"express\": \"^4.18.0\",\n    \"http-errors\": \"^2.0.0\",\n    \"sync-request\": \"^3.0.0\",\n    \"ts-node\": \"^10.7.0\"\n  }\n}\n","path":"code/1531/24T1/4.2/package.json","fileext":"json"},"post_example.ts":{"name":"post_example.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.json());\n\napp.post('/hello', (req, res) => {\n  const name = req.query.body;\n  res.json({\n    name: `Name is ${name}`,\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/24T1/4.2/post_example.ts","fileext":"ts"},"requests.test.ts":{"name":"requests.test.ts","content":"import request from 'sync-request';\n\nfunction get(route: string, qs: any) {\n  const res = request(\n    'GET',\n    `http://localhost:3001${route}`,\n    {\n      qs: qs,\n    }\n  );\n  return JSON.parse(String(res.getBody()));\n}\n\ndescribe('Test Apple', () => {\n  test('If it returns a name string successfully', () => {\n    const bodyObj = get('/apple', {\n      name: 'Hayden',\n    });\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending apple!');\n  });\n});\ndescribe('Test Orange', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'POST',\n      'http://localhost:3001/orange',\n      {\n        json: { name: 'Hayden' },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending orange!');\n  });\n});\n","path":"code/1531/24T1/4.2/requests.test.ts","fileext":"ts"},"requests.ts":{"name":"requests.ts","content":"import request from 'sync-request-curl';\n\nconst res = request(\n  'GET',\n  'http://localhost:3001/apple',\n  {\n    qs: {\n      name: 'Hayden',\n    }\n  }\n);\n\nconsole.log(JSON.parse(String(res.getBody())));\n","path":"code/1531/24T1/4.2/requests.ts","fileext":"ts"},"requests_json.test.ts":{"name":"requests_json.test.ts","content":"import request from 'sync-request';\n\ndescribe('Test Apple', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'GET',\n      'http://localhost:3001/apple',\n      {\n        qs: {\n          name: 'Hayden',\n        },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending apple!');\n  });\n});\ndescribe('Test Orange', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'POST',\n      'http://localhost:3001/orange',\n      {\n        json: { name: 'Hayden' },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending orange!');\n  });\n});\n","path":"code/1531/24T1/4.2/requests_json.test.ts","fileext":"ts"},"tsconfig.json":{"name":"tsconfig.json","content":"{\n    \"compilerOptions\": {\n        \"esModuleInterop\": true,\n        \"noImplicitAny\": false,\n        \"noEmit\": true,\n        \"resolveJsonModule\": true\n    },\n    \"exclude\": [\n      \"**/**_broken.ts\"\n    ]\n}\n\n","path":"code/1531/24T1/4.2/tsconfig.json","fileext":"json"}}},"__N_SSG":true}