Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http from 'node:http'
import { serveStatic } from './utils/serveStatic.js'
import { handleGet } from './handlers/routeHandlers.js'
import { handlePost } from './handlers/routeHandlers.js'

const PORT = 8000

Expand All @@ -12,11 +13,9 @@ const server = http.createServer(async (req, res) => {
if (req.method === 'GET') {
return await handleGet(res)
}
/*
Challenge:
1. Add a route for a POST request to '/api'.
2. When a request comes in, pass the req and res to handlePost().
*/
else if (req.method === 'POST') {
return await handlePost(req, res)
}
}
else if (!req.url.startsWith('/api')) {
return await serveStatic(req, res, __dirname)
Expand Down