CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
TristonStuart

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

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