diff --git a/cache/.key.sample b/cache/.key.sample new file mode 100644 index 0000000..b4408fc --- /dev/null +++ b/cache/.key.sample @@ -0,0 +1 @@ +db597413fa4f4a8545b0f2bb43262f11 \ No newline at end of file diff --git a/cache/cache.js b/cache/app.js similarity index 88% rename from cache/cache.js rename to cache/app.js index 4145f9b..e79b53f 100644 --- a/cache/cache.js +++ b/cache/app.js @@ -2,9 +2,13 @@ const http = require('http') const https = require('https') // 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 HOST = '0.0.0.0' const REGEXP = { URL: /^\/[\d]{1,8}$/ @@ -67,7 +71,7 @@ function getUrlFromPath(path) { return path.replace('/', '') } -const server = http.createServer(async(req, res) => { +const server = http.createServer(async (req, res) => { const zip = getUrlFromPath(req.url) // Check if url is valid @@ -96,8 +100,8 @@ function exit() { } function start() { - console.log(`Started server on: ${LISTEN}`) - server.listen(LISTEN) + console.log(`Started server on: ${LISTEN}. Using Key: ${APP_KEY}`) + server.listen(LISTEN, HOST) } // Register exit function diff --git a/cache/docker-compose.yml b/cache/docker-compose.yml new file mode 100644 index 0000000..dfecfec --- /dev/null +++ b/cache/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3.5" + +services: + cache: + build: . + user: nobody + ports: + - 8000:8000 + restart: always \ No newline at end of file diff --git a/cache/dockerfile b/cache/dockerfile new file mode 100644 index 0000000..e49dea9 --- /dev/null +++ b/cache/dockerfile @@ -0,0 +1,10 @@ +FROM node:alpine + +EXPOSE 80 + +WORKDIR /app +USER nobody +COPY ./app.js ./.key ./ + +ENTRYPOINT [ "node" ] +CMD [ "app.js" ] \ No newline at end of file