|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -const express = require('express'); |
16 | | -const handlebars = require('handlebars'); |
17 | | -const {readFile} = require('fs').promises; |
18 | | -const renderRequest = require('./render.js'); |
| 15 | +import express from 'express'; |
| 16 | +import handlebars from 'handlebars'; |
| 17 | +import fs from 'fs'; |
| 18 | +import renderRequest from './render.js'; |
19 | 19 |
|
20 | 20 | const app = express(); |
21 | 21 | app.use(express.json()); |
22 | 22 |
|
23 | 23 | let markdownDefault, compiledTemplate, renderedHtml; |
24 | 24 |
|
25 | 25 | // Load the template files and serve them with the Editor service. |
26 | | -const buildRenderedHtml = async () => { |
| 26 | +export const buildRenderedHtml = async () => { |
| 27 | + const dirname = process.cwd(); |
27 | 28 | try { |
28 | | - markdownDefault = await readFile(__dirname + '/templates/markdown.md'); |
| 29 | + markdownDefault = await fs.promises.readFile( |
| 30 | + dirname + '/templates/markdown.md' |
| 31 | + ); |
29 | 32 | compiledTemplate = handlebars.compile( |
30 | | - await readFile(__dirname + '/templates/index.html', 'utf8') |
| 33 | + await fs.promises.readFile(dirname + '/templates/index.html', 'utf8') |
31 | 34 | ); |
32 | 35 | renderedHtml = compiledTemplate({default: markdownDefault}); |
33 | 36 | return renderedHtml; |
@@ -62,7 +65,4 @@ app.post('/render', async (req, res) => { |
62 | 65 | // [END cloudrun_secure_request_do] |
63 | 66 |
|
64 | 67 | // Exports for testing purposes. |
65 | | -module.exports = { |
66 | | - app, |
67 | | - buildRenderedHtml, |
68 | | -}; |
| 68 | +export default app; |
0 commit comments