This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include the node10-express-service template
Signed-off-by: Burton Rheutan <[email protected]>
- Loading branch information
Showing
7 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
FROM openfaas/of-watchdog:0.5.3 as watchdog | ||
|
||
FROM node:10.12.0-alpine as ship | ||
|
||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
|
||
RUN addgroup -S app && adduser -S -g app app | ||
|
||
RUN apk --no-cache add ca-certificates | ||
|
||
WORKDIR /root/ | ||
|
||
# Turn down the verbosity to default level. | ||
ENV NPM_CONFIG_LOGLEVEL warn | ||
|
||
RUN mkdir -p /home/app | ||
|
||
# Wrapper/boot-strapper | ||
WORKDIR /home/app | ||
COPY package.json ./ | ||
|
||
# This ordering means the npm installation is cached for the outer function handler. | ||
RUN npm i | ||
|
||
# Copy outer function handler | ||
COPY index.js ./ | ||
|
||
# COPY function node packages and install, adding this as a separate | ||
# entry allows caching of npm install | ||
WORKDIR /home/app/function | ||
COPY function/*.json ./ | ||
RUN npm i || : | ||
|
||
# COPY function files and folders | ||
COPY function/ ./ | ||
|
||
# Set correct permissions to use non root user | ||
WORKDIR /home/app/ | ||
|
||
# chmod for tmp is for a buildkit issue (@alexellis) | ||
RUN chown app:app -R /home/app \ | ||
&& chmod 777 /tmp | ||
|
||
USER app | ||
|
||
ENV cgi_headers="true" | ||
ENV fprocess="node index.js" | ||
ENV mode="http" | ||
ENV upstream_url="http://127.0.0.1:3000" | ||
|
||
ENV exec_timeout="10s" | ||
ENV write_timeout="15s" | ||
ENV read_timeout="15s" | ||
|
||
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
CMD ["fwatchdog"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict" | ||
|
||
module.exports = async (config) => { | ||
const routing = new Routing(config.app); | ||
routing.configure(); | ||
routing.bind(routing.handle); | ||
} | ||
|
||
class Routing { | ||
constructor(app) { | ||
this.app = app; | ||
} | ||
|
||
configure() { | ||
const bodyParser = require('body-parser') | ||
this.app.use(bodyParser.json()); | ||
this.app.use(bodyParser.raw()); | ||
this.app.use(bodyParser.text({ type : "text/*" })); | ||
this.app.disable('x-powered-by'); | ||
} | ||
|
||
bind(route) { | ||
this.app.post('/*', route); | ||
this.app.get('/*', route); | ||
this.app.patch('/*', route); | ||
this.app.put('/*', route); | ||
this.app.delete('/*', route); | ||
} | ||
|
||
handle(req, res) { | ||
res.send(JSON.stringify(req.body)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "function", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "handler.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Alex Ellis 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
"use strict" | ||
|
||
const express = require('express') | ||
const app = express() | ||
const handler = require('./function/handler'); | ||
|
||
async function init() { | ||
await handler({"app": app}); | ||
|
||
const port = process.env.http_port || 3000; | ||
app.disable('x-powered-by'); | ||
|
||
app.listen(port, () => { | ||
console.log(`node10-express-service, listening on port: ${port}`) | ||
}); | ||
} | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "node10-express", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"body-parser": "^1.18.2", | ||
"express": "^4.16.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: node10-express-service | ||
fprocess: node index.js |