Skip to content

Commit

Permalink
Async server
Browse files Browse the repository at this point in the history
  • Loading branch information
dqj1998 committed Jul 30, 2022
1 parent aef7567 commit 9ecaae6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const http = require("http");

const port = 3000;
const server = http.createServer();

server.on('request', AppController);

server.listen(port);
console.log(`Started server: ${port}`);

const server = http.createServer((request, response) => {

async function AppController(request, response) {
const url = new URL(request.url, `http://${request.headers.host}`)

if(request.method === 'GET') {
Expand All @@ -17,9 +25,7 @@ const server = http.createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(html);
}else if(request.method === 'POST') {

}

});

server.listen(port);
console.log(`Started server: ${port}`);
}

0 comments on commit 9ecaae6

Please sign in to comment.