UNPKG

molstar

Version:

A comprehensive macromolecular library.

63 lines 2.41 kB
/** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator } from "tslib"; import express from 'express'; import fetch from 'node-fetch'; import { createMapping } from './mapping'; function getMappings(id) { return __awaiter(this, void 0, void 0, function () { var data, json; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch("https://www.ebi.ac.uk/pdbe/api/mappings/" + id)]; case 1: data = _a.sent(); return [4 /*yield*/, data.json()]; case 2: json = _a.sent(); return [2 /*return*/, createMapping(json)]; } }); }); } ; var PORT = process.env.port || 1338; var app = express(); var PREFIX = '/'; app.get(PREFIX + "/:id", function (req, res) { return __awaiter(void 0, void 0, void 0, function () { var mapping, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 2, , 3]); console.log('Requesting ' + req.params.id); return [4 /*yield*/, getMappings(req.params.id)]; case 1: mapping = _b.sent(); res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'X-Requested-With' }); res.end(mapping); return [3 /*break*/, 3]; case 2: _a = _b.sent(); console.log('Failed ' + req.params.id); res.writeHead(404, { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'X-Requested-With' }); res.end(); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }); app.get("" + PREFIX, function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end('Usage: /pdb_id, e.g. /1tqn'); }); app.listen(PORT); console.log('Running on port ' + PORT); //# sourceMappingURL=server.js.map