Skip to content

Commit

Permalink
Add standalone server
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Aug 29, 2018
1 parent adf8d46 commit 285124e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.2.0 / 2018-08-29
------------------
* Add standalone server

2.1.4 / 2018-08-22
------------------
* Fix bug
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "summaly",
"version": "2.1.4",
"version": "2.2.0",
"description": "Get web page's summary",
"author": "syuilo <i@syuilo.com>",
"license": "MIT",
Expand All @@ -13,22 +13,23 @@
"test": "mocha --harmony"
},
"devDependencies": {
"@types/express": "4.16.0",
"@types/debug": "0.0.30",
"@types/express": "4.16.0",
"@types/html-entities": "1.2.16",
"@types/mocha": "5.2.2",
"@types/request": "2.47.1",
"@types/node": "10.3.4",
"@types/request": "2.47.1",
"@types/request-promise-native": "1.0.15",
"express": "4.16.3",
"typescript": "2.9.2",
"mocha": "5.2.0"
"mocha": "5.2.0",
"typescript": "2.9.2"
},
"dependencies": {
"cheerio-httpcli": "0.7.3",
"debug": "3.1.0",
"escape-regexp": "0.0.1",
"html-entities": "1.2.1",
"koa": "2.5.2",
"request": "2.87.0",
"request-promise-native": "1.0.5",
"require-all": "2.2.0",
Expand Down
21 changes: 21 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as http from 'http';
import * as Koa from 'koa';
import summaly from '../';

const app = new Koa();

app.use(async ctx => {
try {
const summary = await summaly(ctx.query.url, {
followRedirects: false
});

ctx.body = summary;
} catch (e) {
ctx.status = 500;
}
});

const server = http.createServer(app.callback());

server.listen(80);

0 comments on commit 285124e

Please sign in to comment.