Skip to content

Commit

Permalink
Got the docx download feature working, changed docker image (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry authored Sep 24, 2019
1 parent a9876fa commit 0053195
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM node:10-alpine
FROM pandoc/core
LABEL maintainer="-"

RUN apk add --update nodejs nodejs-npm

ARG GITHUB_SHA_ARG

COPY . /src
Expand All @@ -11,4 +13,7 @@ RUN npm install --quiet --production

EXPOSE 3000

# heroku needs this
CMD [ "npm", "start" ]

ENTRYPOINT [ "npm", "start" ]
1 change: 1 addition & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "",
"formation": {},
"addons": [],
"stack": "container",
"buildpacks": [
{
"url": "heroku/nodejs"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const routes = [
{ name: 'landing-page', path: '/' },
{ name: 'questions-1', path: '/questions-1' },
{ name: 'agreement-1', path: '/agreement-1' },
{ name: 'participant-consent-form', path: '/participant-consent-form' },
{ name: 'confirmation', path: '/confirmation' },
{ name: 'participant-consent-form', path: '/participant-consent-form' },
{ name: 'personal', path: '/personal' },
]

Expand Down
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"express-validator": "^6.2.0",
"helmet": "^3.21.0",
"i18n": "^0.8.3",
"node-pandoc": "^0.3.0",
"node-sass": "^4.12.0",
"node-sass-middleware": "^0.11.0",
"normalize.css": "^8.0.1",
Expand Down
4 changes: 4 additions & 0 deletions public/documents/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
30 changes: 28 additions & 2 deletions routes/agreement-1/agreement-1.controller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
const path = require('path')
const { getNextRoute, routeUtils } = require('./../../utils')
const { Schema } = require('./schema.js')
var nodePandoc = require("node-pandoc");

var callback = (err, result) => {
if (err) {
console.error(err);
} else {
console.log("done conversion");
}
};

function getRandomString() {
return Math.random().toString().split(".")[1].slice(0,8);
}

module.exports = app => {
const name = 'agreement-1'
const route = routeUtils.getRouteByName(name)

routeUtils.addViewPath(app, path.join(__dirname, './'))

app
app
.get(route.path, (req, res) => {
res.render(name, { ...routeUtils.getViewData(req, {}), nextRoute: getNextRoute(name).path })
var randomString = getRandomString()
var docxFilename = "agreement-" + randomString + ".docx"

res.render(name, {
...routeUtils.getViewData(req, {}),
nextRoute: getNextRoute(name).path,
docxFilename: docxFilename,
}, function(err, html) {
if(err) {
console.log(err)
}
nodePandoc(html, "-f html -t docx -o public/documents/" + docxFilename, callback)
res.send(html);
})
})
.post(route.path, [
...routeUtils.getDefaultMiddleware({ schema: Schema, name: name }),
Expand Down
2 changes: 2 additions & 0 deletions routes/agreement-1/agreement-1.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% block content %}

<a href={{ "documents/" + docxFilename }}>Download Word Document</a>

<h1>Proof of Concept Agreement</h1>

<div>
Expand Down

0 comments on commit 0053195

Please sign in to comment.