diff --git a/index.js b/index.js index afc6a8bd6c..9e74c4dd85 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,25 @@ -const express = require('express') -const app = express() -app.all('/', (req, res) => { - console.log("Just got a request!") - res.send('Yo!') -}) -app.listen(process.env.PORT || 3000) \ No newline at end of file +const http = require('http'); +const url = require('url'); + +const server = http.createServer((req, res) => { + + req.query = url.parse(req.url, true).query; + const radius = req.query.radius; + + if (radius === undefined) { + res.statusCode = 400; + res.setHeader('Content-Type', 'text/plain'); + res.end('Nama: Vincent Sompie\nNIM: 210211060120\n\nError: Silahkan memasukkan parameter radius pada request query.\n'); + } else { + const area = Math.PI * radius ** 2; + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.end(`Nama: Vincent Sompie\nNIM: 210211060120\n\nLuas lingkaran dengan jari-jari ${radius} adalah ${area}.\n`); + } +}); + +const PORT = 3000 + +server.listen(PORT, () => { + console.log(`Server up and running at port ${PORT}`); +});