Skip to content

Commit

Permalink
Merge pull request #17 from onaio/remove-express-upgrade-node
Browse files Browse the repository at this point in the history
Remove express and upgrade node version
  • Loading branch information
ciremusyoka authored Sep 25, 2024
2 parents 4c6788f + e5e39f5 commit e164c74
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 559 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# adapted from https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
FROM node:20.15.1-alpine3.20
FROM node:20.17.0-alpine3.20
RUN apk update && apk upgrade
WORKDIR /usr/src/app
COPY package*.json ./
Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ const axios = require("axios");

async function build() {
const fastify = require("fastify")({ logger: logger });
await fastify.register(require('@fastify/express'));
const queryString = require("query-string");
fastify.use((req, res, done) => {
fastify.addHook('onRequest', async (req, reply) => {
reqParams = req.url.split("?")[1];
const parsedReqParams = queryString.parse(reqParams);
const formId = parsedReqParams.form_id;
tempToken = parsedReqParams.temp_token;
const tempToken = parsedReqParams.temp_token;
if (formId) {
axios
.get(`${process.env.FORMS_ENDPOINT}${formId}.json`, {
Expand All @@ -31,19 +30,19 @@ async function build() {
})
.then((res) => {
if (res && res.status === 200) {
done();
return;
} else {
done("Forbidden");
reply.code(403).send("Forbidden");
}
})
.catch((error) => {
req.log.error(error)
done(error.detail);
reply.code((error?.status || 500)).send(error.message);
});
} else if ("/health-check" == req.url) {
done()
return;
} else {
done("Authentication Failure");
reply.code(401).send("Authentication Failure");
}
});

Expand Down
Loading

0 comments on commit e164c74

Please sign in to comment.