|
|
|
@ -3,6 +3,7 @@ const url = require('url')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const ws = require('ws')
|
|
|
|
|
const redis = require('redis')
|
|
|
|
|
const mime = require('mime')
|
|
|
|
|
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest
|
|
|
|
|
const host = 'http://127.0.0.1:8080/'
|
|
|
|
|
|
|
|
|
@ -19,17 +20,18 @@ http.createServer(function (req, res) {
|
|
|
|
|
const q = url.parse(req.url, true);
|
|
|
|
|
let filename = "./public" + q.pathname;
|
|
|
|
|
if (filename === "./public/") filename = "./public/index.html";
|
|
|
|
|
let file_type = mime.getType(filename)
|
|
|
|
|
//q.pathname.split("/", 2)[1] === "sym" || )
|
|
|
|
|
if (function valid_path(){
|
|
|
|
|
if (function valid_path(){//
|
|
|
|
|
for (let i = 0; i < outpath.length; i++) if (q.pathname.split("/", 2)[1] === outpath[i]) return true
|
|
|
|
|
return false
|
|
|
|
|
}() === true){
|
|
|
|
|
fs.readFile(filename, function(err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
res.writeHead(404, {'Content-Type': 'text/html'});
|
|
|
|
|
res.writeHead(404, {'Content-Type': file_type});
|
|
|
|
|
return res.end("404 Not Found");
|
|
|
|
|
}
|
|
|
|
|
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
|
|
|
res.writeHead(200, {'Content-Type': file_type});
|
|
|
|
|
res.write(data);
|
|
|
|
|
return res.end();
|
|
|
|
|
})
|
|
|
|
@ -40,7 +42,7 @@ http.createServer(function (req, res) {
|
|
|
|
|
res.writeHead(302, {'Location': obj});
|
|
|
|
|
return res.end();
|
|
|
|
|
}else{
|
|
|
|
|
res.writeHead(404, {'Content-Type': 'text/html'});
|
|
|
|
|
res.writeHead(404, {'Content-Type': file_type});
|
|
|
|
|
return res.end("404 this short-url does not exist :/");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|