Skip to content

Commit

Permalink
fixed issue with send
Browse files Browse the repository at this point in the history
  • Loading branch information
SheetJSDev committed Oct 20, 2018
1 parent 77aa1c1 commit 725c2b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<title>SheetJS Spreadsheet Conversion Service</title>
<link rel="icon" type="image/png" href="//rawgit.com/SheetJS/SheetJS.github.io/master/assets/img/logo.png"/>
<link rel="icon" type="image/png" href="//sheetjs.com/logo.png"/>
</head>
<body>
<style> a { text-decoration: none } </style>
Expand Down
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var XLSX = require('xlsx');
var URL = require('url');
var request = require('request');
var send = require('send');
var micro = require('micro');

var fs = require("fs");
var HTML = fs.readFileSync("index.html");

function do_url(req, url, res) {
request(url.query.url, {encoding:null}, function(err, response, body) {
if(err) return micro.send(res, 500, err);
Expand All @@ -29,18 +31,21 @@ function do_url(req, url, res) {
}
});
}
send.mime.default_type="text/html";

module.exports = function(req, res) {
var url = URL.parse(req.url, true);
if(url.pathname == "/") {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
return send(req, "index.html").pipe(res);
res.writeHead(200, {
'Content-Type': 'text/html; charset=UTF-8'
});
res.end(HTML);
return;
}
res.setHeader('Access-Control-Allow-Origin', '*');
var mode = -1;
if(url.query.url) mode = 0;
if(mode == -1) return micro.send(res, 500, "Must issue command");
if(mode == -1) { micro.send(res, 500, "Must issue command"); return; }
switch(mode) {
case 0: return do_url(req, url, res);
case 0: do_url(req, url, res); break;
}
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dependencies": {
"micro":"",
"request":"",
"send":"",
"xlsx":""
},
"scripts": {
Expand Down

0 comments on commit 725c2b1

Please sign in to comment.