UNPKG

molstar

Version:

A comprehensive macromolecular library.

65 lines 2.65 kB
"use strict"; /** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var express_1 = (0, tslib_1.__importDefault)(require("express")); var node_fetch_1 = (0, tslib_1.__importDefault)(require("node-fetch")); var mapping_1 = require("./mapping"); function getMappings(id) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var data, json; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, node_fetch_1.default)("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*/, (0, mapping_1.createMapping)(json)]; } }); }); } ; var PORT = process.env.port || 1338; var app = (0, express_1.default)(); var PREFIX = '/'; app.get(PREFIX + "/:id", function (req, res) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () { var mapping, _a; return (0, tslib_1.__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