fixed issue with send
This commit is contained in:
parent
77aa1c1df8
commit
725c2b1795
@ -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>
|
||||
|
17
index.js
17
index.js
@ -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);
|
||||
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -7,7 +7,6 @@
|
||||
"dependencies": {
|
||||
"micro":"",
|
||||
"request":"",
|
||||
"send":"",
|
||||
"xlsx":""
|
||||
},
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user