generated from skills/copilot-codespaces-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d788068
commit de7691e
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Create web server | ||
// 1. Include http module | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
var url = require('url'); | ||
var path = require('path'); | ||
|
||
// 2. Create server | ||
http.createServer(function (req, res) { | ||
// Parse the request containing file name | ||
var pathname = url.parse(req.url).pathname; | ||
// Print the name of the file for which request is made. | ||
console.log("Request for " + pathname + " received."); | ||
|
||
// Read the requested file content from file system | ||
fs.readFile(pathname.substr(1), function (err, data) { | ||
if (err) { | ||
console.log(err); | ||
// HTTP Status: 404 : NOT FOUND | ||
// Content Type: text/plain | ||
res.writeHead(404, { 'Content-Type': 'text/html' }); | ||
} else { | ||
// Page found | ||
// HTTP Status: 200 : OK | ||
// Content Type: text/plain | ||
res.writeHead(200, { 'Content-Type': 'text/html' }); | ||
|
||
// Write the content of the file to response body | ||
res.write(data.toString()); | ||
} | ||
// Send the response body | ||
res.end(); | ||
}); | ||
}).listen(8080); | ||
|
||
// Console will print the message | ||
console.log('Server running at http:// |