ffffng/server/resources/frontendResource.js

31 lines
887 B
JavaScript
Raw Normal View History

2016-06-07 14:08:04 +02:00
'use strict';
2018-12-17 22:49:54 +01:00
const fs = require('graceful-fs')
2016-06-07 14:08:04 +02:00
2018-12-17 22:49:54 +01:00
const ErrorTypes = require('../utils/errorTypes')
const Logger = require('../logger')
const Resources = require('../utils/resources')
2016-06-07 14:08:04 +02:00
2018-12-17 22:49:54 +01:00
const indexHtml = __dirname + '/../../client/index.html';
2016-06-07 14:08:04 +02:00
2018-12-17 22:49:54 +01:00
module.exports = {
render (req, res) {
const data = Resources.getData(req);
fs.readFile(indexHtml, 'utf8', function (err, body) {
if (err) {
Logger.tag('frontend').error('Could not read file: ', indexHtml, err);
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
}
return Resources.successHtml(
res,
body.replace(
/<body/,
'<script>window.__nodeToken = \''+ data.token + '\';</script><body'
)
);
});
}
}