Created
July 26, 2019 17:06
-
-
Save justengland/d990cbb058b8c979ba1419c2d60a690a to your computer and use it in GitHub Desktop.
Self-signed node docker setup
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
const express = require('express') | |
const fs = require('fs') | |
const https = require('https') | |
const querystring = require('querystring'); | |
const port = process.env.PORT || 3000 | |
const PING_PATH = '/ping' | |
const options = { | |
key: fs.readFileSync( './localhost.key' ), | |
cert: fs.readFileSync( './localhost.cert' ), | |
requestCert: false, | |
rejectUnauthorized: false | |
}; | |
const app = express() | |
const server = https.createServer( options, app ); | |
server.listen(port, function () { | |
console.log( 'Express server listening on port ' + server.address().port ); | |
}); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: false })); | |
// Application heart beat | |
app.get(PING_PATH, async(req, res) => { | |
res.send('pong') | |
}) | |
app.all('*', async (req, res, next) => { | |
console.log('request:', req) | |
const {path, body, query} = req | |
// If the site is pinged ignore the deep logging | |
if(path === PING_PATH) { | |
next() | |
} else { | |
// Fire and forget | |
res.send('thanks') | |
await log([{path, body, query}]) | |
} | |
}) | |
// app.listen(port, () => { | |
// console.log(`Click data application ${port}!`) | |
// }) | |
async function log(data) { | |
setTimeout(() => { | |
console.log('----------------------------------------------------------------') | |
console.log(JSON.stringify(data, 0, 2)) | |
console.log('----------------------------------------------------------------') | |
}) | |
} | |
// app.use(logger('dev')); | |
// app.use(express.json()); | |
// app.use(express.urlencoded({ extended: false })); | |
// app.use(express.static(path.join(__dirname, 'public'))); | |
// | |
// var port = process.env.PORT || 3000 | |
// | |
// // error handler | |
// app.use(function(err, req, res, next) { | |
// // // set locals, only providing error in development | |
// // res.locals.message = err.message; | |
// // res.locals.error = req.app.get('env') === 'development' ? err : {}; | |
// | |
// // render the error page | |
// // res.status(err.status || 500); | |
// // res.render('error'); | |
// | |
// next() | |
// }); | |
// | |
// // request handler | |
// app.use(function(err, req, res) { | |
// | |
// res.render('ok'); | |
// | |
// }); | |
// | |
// app.listen(port); | |
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
FROM node:10 | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
RUN apt-get update && \ | |
apt-get install -y openssl && \ | |
openssl genrsa -out localhost.key 2048 && \ | |
openssl req -new -x509 -key localhost.key -out localhost.cert -days 3650 -subj /CN=localhost | |
# Setup click_data user | |
RUN groupadd click_data && \ | |
useradd click_data -g click_data && \ | |
mkdir -p /home/click_data/ && \ | |
chown -R click_data:click_data /home/click_data && \ | |
# chmod +x test.sh && \ | |
# chmod +x entrypoint.sh && \ | |
# chmod +x setup-config.py && \ | |
# chmod +x add-rds-user.py && \ | |
chown -R click_data:click_data /usr/src/app && \ | |
chmod -R 755 /root/ | |
# USER click_data | |
EXPOSE 3000 | |
CMD [ "node", "app" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment