diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b4bb16e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +.git +config.json +certs +src/logs diff --git a/.gitignore b/.gitignore index e43b0f9..78a27fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .DS_Store +node_modules +certs +config.json +src/logs diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..be1b7af --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:18-alpine + +RUN apk add --no-cache python3 make gcc g++ +WORKDIR /app + +COPY "docker/entrypoint.sh" ./ + +COPY package*.json ./ +RUN npm install + +COPY . ./ + +VOLUME [ "/app/config.json", "/app/certs" ] + +CMD ["sh", "entrypoint.sh"] diff --git a/README.md b/README.md index f89f5a3..423a810 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # What is this? This is the Pretendo Network Miiverse API Server, which replaces the former Nintendo Network Miiverse API Server *.olv.nintendo.net # Install and usage -First install [NodeJS](https://nodejs.org) and [MongoDB](https://mongodb.com). Download/clone this repo and run `npm i` to install all dependencies. Edit `src/config.json` to your liking. Run the server via `npm run start`. +First install [NodeJS](https://nodejs.org) and [MongoDB](https://mongodb.com). Download/clone this repo and run `npm i` to install all dependencies. Create a `config.json` to your liking (example in `config.example.json`). Run the server via `npm run start`. # To-Do - [x] Discovery Server - [x] Posts Server diff --git a/src/config.json b/config.example.json similarity index 100% rename from src/config.json rename to config.example.json diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..8580413 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +files='config.json certs/access/private.pem certs/access/aes.key' + +for file in $files; do + if [ ! -f $file ]; then + echo "$PWD/$file file does not exist. Please mount and try again." + exit 1 + fi +done + +exec node src/server.js diff --git a/src/database.js b/src/database.js index d2cd013..893e77e 100644 --- a/src/database.js +++ b/src/database.js @@ -1,5 +1,5 @@ const mongoose = require('mongoose'); -const { mongoose: mongooseConfig } = require('./config.json'); +const { mongoose: mongooseConfig } = require('../config.json'); const { ENDPOINT } = require('./models/endpoint'); const { COMMUNITY } = require('./models/communities'); const { POST } = require('./models/post'); diff --git a/src/server.js b/src/server.js index 625d3a4..005b3bb 100644 --- a/src/server.js +++ b/src/server.js @@ -4,7 +4,7 @@ const morgan = require('morgan'); const xmlparser = require('./middleware/xml-parser'); const database = require('./database'); const logger = require('./logger'); -const config = require('./config.json'); +const config = require('../config.json'); const { http: { port } } = config; const app = express(); diff --git a/src/util/util.js b/src/util/util.js index 15c1733..b26bb84 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -2,7 +2,7 @@ const crypto = require('crypto'); const NodeRSA = require('node-rsa'); const fs = require('fs-extra'); const database = require('../database'); -const config = require('../config.json'); +const config = require('../../config.json'); const xmlParser = require('xml2json'); const request = require("request"); const moment = require('moment');