Moved to docker for production

This commit is contained in:
nicco 2018-02-23 11:13:13 +01:00
parent 8ae8e99897
commit 2b91123838
4 changed files with 28 additions and 4 deletions

1
cache/.key.sample vendored Normal file
View File

@ -0,0 +1 @@
db597413fa4f4a8545b0f2bb43262f11

View File

@ -2,9 +2,13 @@ const http = require('http')
const https = require('https') const https = require('https')
// GET YOUR OWN AT: https://openweathermap.org/appid // GET YOUR OWN AT: https://openweathermap.org/appid
const APP_KEY = 'db597413fa4f4a8545b0f2bb43262f11' const APP_KEY = require('fs').readFileSync(__dirname + '/.key', {
encoding: 'utf-8',
flag: 'r'
}).trim()
const LISTEN = '8000' const LISTEN = '8000'
const HOST = '0.0.0.0'
const REGEXP = { const REGEXP = {
URL: /^\/[\d]{1,8}$/ URL: /^\/[\d]{1,8}$/
@ -67,7 +71,7 @@ function getUrlFromPath(path) {
return path.replace('/', '') return path.replace('/', '')
} }
const server = http.createServer(async(req, res) => { const server = http.createServer(async (req, res) => {
const zip = getUrlFromPath(req.url) const zip = getUrlFromPath(req.url)
// Check if url is valid // Check if url is valid
@ -96,8 +100,8 @@ function exit() {
} }
function start() { function start() {
console.log(`Started server on: ${LISTEN}`) console.log(`Started server on: ${LISTEN}. Using Key: ${APP_KEY}`)
server.listen(LISTEN) server.listen(LISTEN, HOST)
} }
// Register exit function // Register exit function

9
cache/docker-compose.yml vendored Normal file
View File

@ -0,0 +1,9 @@
version: "3.5"
services:
cache:
build: .
user: nobody
ports:
- 8000:8000
restart: always

10
cache/dockerfile vendored Normal file
View File

@ -0,0 +1,10 @@
FROM node:alpine
EXPOSE 80
WORKDIR /app
USER nobody
COPY ./app.js ./.key ./
ENTRYPOINT [ "node" ]
CMD [ "app.js" ]