-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathindex.js
45 lines (42 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Get http, fs, and path
const http = require('http');
const fs = require('fs');
const path = require('path');
// Log
console.log("Server Running (Hopefully)")
// Start a server at port 8000
http.createServer((request, response) => {
console.log(request.url);
// Check if this is a mod.js request
if (request.url == "/shellshock.min.js"){
// Set Content Type
let contentType = "text/javascript";
// Define file path (You can change if you place file in another location)
let filePath = "." + request.url;
// Read file
fs.readFile(filePath, (error, content) => {
if (error){
if (error.code == 'ENOENT'){
console.error("Mod.js file is not found!");
response.writeHead(200, {'Content-Type': contentType});
response.end('', 'utf-8');
}else {
console.error("No Idea : " + error.code);
response.writeHead(200, {'Content-Type': contentType});
response.end('', 'utf-8');
}
}else {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET, POST');
response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
response.setHeader('Access-Control-Allow-Credentials', true);
response.writeHead(200, {'Content-Type': contentType});
response.end(content, 'utf-8');
}
});
}else {
response.writeHead(200, {'Content-type':'text/plan'});
response.write('Invalid URL Try : http://localhost:8000/mod.js');
response.end();
}
}).listen(8000);