ng-spec-shot-reviewer
Version:
combined server of spec shot reviewer backend and optionally multiple static websites (e.g. compiled angular apps)
47 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const express_1 = require("express");
const server_1 = require("./server");
const cors = require("cors");
var corsOptions = {
origin: 'http://localhost:4200',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
};
class SsrEndpoint {
constructor(serverCfg) {
this.router = express_1.Router();
this.server = new server_1.FsSsrServer(serverCfg);
this.router.use('*', cors(corsOptions));
this.router.get('/test', (_, res) => res.send('Ok'));
this.router.put('/spec-shot/:id/approve', (req, res) => {
this.server.approve(encodeURIComponent(req.params['id']))
.then(() => res.sendStatus(200))
.catch((e) => res.send(e).sendStatus(400));
});
this.router.put('/spec-shot/:id/disapprove', (req, res) => {
this.server.disapprove(encodeURIComponent(req.params['id']))
.then(() => res.sendStatus(200))
.catch((e) => res.send(e).sendStatus(400));
});
this.router.get('/spec-shot', (req, res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (req.headers['cache-control'] === 'no-cache') {
this.server.refresh();
}
res.send(JSON.stringify(yield this.server.specShots()));
}));
this.router.post('/applyApprovements', express_1.json(), (req, res) => {
this.server.applyApprovements(req.body.ids)
.then((updatedSpecShots) => res.send(updatedSpecShots))
.catch((e) => res.send(e).sendStatus(400));
});
this.router.use('/image/actual', express_1.static(serverCfg.directories.actual));
this.router.use('/image/diff', express_1.static(serverCfg.directories.diff));
this.router.use('/image/baseline', express_1.static(serverCfg.directories.baseline));
}
get middleware() {
return this.router;
}
}
exports.SsrEndpoint = SsrEndpoint;
//# sourceMappingURL=endpoint.js.map