Typescript migration:

* resources/frontendResource.js
* resources/taskResource.js
* resources/versionResource.js

Also some refactoring towards using promises with async / await.
This commit is contained in:
baldo 2020-04-09 20:18:13 +02:00
parent b1755047af
commit 31ecc0cf4f
10 changed files with 191 additions and 196 deletions
server/resources

View file

@ -0,0 +1,26 @@
import {promises as fs} from "graceful-fs";
import ErrorTypes from "../utils/errorTypes";
import Logger from "../logger";
import * as Resources from "../utils/resources";
import {Request, Response} from "express";
const indexHtml = __dirname + '/../../client/index.html';
export function render (req: Request, res: Response): void {
const data = Resources.getData(req);
fs.readFile(indexHtml, 'utf8')
.then(body =>
Resources.successHtml(
res,
body.replace(
/<body/,
'<script>window.__nodeToken = \''+ data.token + '\';</script><body'
)
))
.catch(err => {
Logger.tag('frontend').error('Could not read file: ', indexHtml, err);
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
})
}