Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cee4ea98f5 | |||
| cdafc4bd79 | |||
| a9485a4d0a | |||
| d0877dd0a9 | |||
| bad631eeae | |||
| 5915ae2733 | |||
| ab7047b9cd | |||
| 23f87d376a | |||
| ffe9b66886 | |||
| c85b689aed | |||
| 22735a9ea6 | |||
| 9367999ef2 | |||
| d42824d41a | |||
| 7d2186860c |
@@ -3,6 +3,8 @@ WEB_PORT=3100
|
|||||||
WEB_ORIGIN=http://localhost:3001
|
WEB_ORIGIN=http://localhost:3001
|
||||||
|
|
||||||
DB_HOSTNAME=localhost
|
DB_HOSTNAME=localhost
|
||||||
|
DB_PORTNAME=3306
|
||||||
|
|
||||||
DB_DATABASE=news
|
DB_DATABASE=news
|
||||||
DB_USERNAME=news
|
DB_USERNAME=news
|
||||||
DB_PASSWORD=venusaur
|
DB_PASSWORD=venusaur
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
|
||||||
|
|
||||||
@@ -5,19 +5,21 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- v1.*
|
- v1.*
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
push_to_registry:
|
push_to_registry:
|
||||||
name: Push Docker Image to Docker Hub
|
name: Push Docker Image to Docker Hub
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check Out The Repo
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Setup QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Get Smart Tag
|
- name: Get Smart Tag
|
||||||
id: prepare
|
id: prepare
|
||||||
@@ -26,13 +28,13 @@ jobs:
|
|||||||
docker_image: krgamestudios/news-server
|
docker_image: krgamestudios/news-server
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Push to Docker Hub
|
- name: Push to Docker Hub
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.prepare.outputs.tag }}
|
tags: ${{ steps.prepare.outputs.tag }}
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
FROM node:21-bookworm-slim
|
FROM node:22-bookworm-slim
|
||||||
WORKDIR "/app"
|
WORKDIR "/app"
|
||||||
COPY package*.json /app
|
COPY package*.json /app
|
||||||
RUN npm install --production
|
RUN npm install --omit=dev
|
||||||
COPY . /app
|
COPY . /app
|
||||||
EXPOSE 3100
|
EXPOSE 3100
|
||||||
USER node
|
USER node
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ This server is available via docker hub at krgamestudios/news-server.
|
|||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
|
|
||||||
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
|
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
|
||||||
|
|
||||||
To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are valid for 10 minutes):
|
To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are valid for 10 minutes):
|
||||||
|
|
||||||
|
|||||||
+53
-25
@@ -33,6 +33,25 @@ const question = (prompt, def = null) => {
|
|||||||
const appWebOrigin = await question('Web Origin', `https://example.com`); //TODO: clean these up properly
|
const appWebOrigin = await question('Web Origin', `https://example.com`); //TODO: clean these up properly
|
||||||
const appPort = await question('App Port', '3100');
|
const appPort = await question('App Port', '3100');
|
||||||
|
|
||||||
|
//configure the database address
|
||||||
|
let dbLocation = '';
|
||||||
|
while (typeof dbLocation != 'string' || /^[le]/i.test(dbLocation[0]) == false) {
|
||||||
|
dbLocation = await question('[l]ocal or [e]xternal database?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let appDBHost = '';
|
||||||
|
let appDBPort = '';
|
||||||
|
|
||||||
|
if (/^[l]/i.test(dbLocation[0])) {
|
||||||
|
appDBHost = 'database';
|
||||||
|
appDBPort = '3306';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
appDBHost = await question('DB Host');
|
||||||
|
appDBPort = await question('DB Port', '3306');
|
||||||
|
}
|
||||||
|
|
||||||
|
//configure the database account
|
||||||
const appDBUser = await question('DB User', appName);
|
const appDBUser = await question('DB User', appName);
|
||||||
const appDBPass = await question('DB Pass', 'venusaur');
|
const appDBPass = await question('DB Pass', 'venusaur');
|
||||||
const dbRootPass = await question('DB Root Pass');
|
const dbRootPass = await question('DB Root Pass');
|
||||||
@@ -43,38 +62,43 @@ const question = (prompt, def = null) => {
|
|||||||
|
|
||||||
//generate the files
|
//generate the files
|
||||||
const ymlfile = `
|
const ymlfile = `
|
||||||
version: '3.8'
|
|
||||||
services:
|
services:
|
||||||
${appName}:
|
${appName}:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
ports:
|
ports:
|
||||||
- "${appPort}"
|
- ${appPort}
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- traefik.enable=true
|
||||||
- "traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)"
|
- traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)
|
||||||
- "traefik.http.routers.${appName}router.entrypoints=websecure"
|
- traefik.http.routers.${appName}router.entrypoints=websecure
|
||||||
- "traefik.http.routers.${appName}router.tls.certresolver=myresolver"
|
- traefik.http.routers.${appName}router.tls.certresolver=myresolver
|
||||||
- "traefik.http.routers.${appName}router.service=${appName}service@docker"
|
- traefik.http.routers.${appName}router.service=${appName}service@docker
|
||||||
- "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}"
|
- traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}
|
||||||
environment:
|
environment:
|
||||||
- WEB_PORT=${appPort}
|
- WEB_PORT=${appPort}
|
||||||
- WEB_ORIGIN=${appWebOrigin}
|
- WEB_ORIGIN=${appWebOrigin}
|
||||||
- DB_HOSTNAME=database
|
- DB_HOSTNAME=${appDBHost}
|
||||||
|
- DB_PORTNAME=${appDBPort}
|
||||||
- DB_DATABASE=${appName}
|
- DB_DATABASE=${appName}
|
||||||
- DB_USERNAME=${appDBUser}
|
- DB_USERNAME=${appDBUser}
|
||||||
- DB_PASSWORD=${appDBPass}
|
- DB_PASSWORD=${appDBPass}
|
||||||
- DB_TIMEZONE=Australia/Sydney
|
- DB_TIMEZONE=Australia/Sydney
|
||||||
- PAGE_SIZE=10
|
- PAGE_SIZE=10
|
||||||
- SECRET_ACCESS=${appSecretAccess}
|
- SECRET_ACCESS=${appSecretAccess}
|
||||||
|
volumes:
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network${ appDBHost != 'database' ? '' : `
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
|
|
||||||
database:
|
database:
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
environment:
|
environment:
|
||||||
MYSQL_DATABASE: ${appName}
|
MYSQL_DATABASE: ${appName}
|
||||||
|
MYSQL_TCP_PORT: ${appDBPort}
|
||||||
MYSQL_USER: ${appDBUser}
|
MYSQL_USER: ${appDBUser}
|
||||||
MYSQL_PASSWORD: ${appDBPass}
|
MYSQL_PASSWORD: ${appDBPass}
|
||||||
MYSQL_ROOT_PASSWORD: ${dbRootPass}
|
MYSQL_ROOT_PASSWORD: ${dbRootPass}
|
||||||
@@ -83,35 +107,39 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./mysql:/var/lib/mysql
|
- ./mysql:/var/lib/mysql
|
||||||
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
|
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro`}
|
||||||
|
|
||||||
traefik_${appName}:
|
traefik_${appName}:
|
||||||
image: "traefik:v2.10"
|
image: traefik:latest
|
||||||
command:
|
command:
|
||||||
- "--log.level=ERROR"
|
- --log.level=ERROR
|
||||||
- "--api.insecure=false"
|
- --api.insecure=false
|
||||||
- "--providers.docker=true"
|
- --providers.docker=true
|
||||||
- "--providers.docker.exposedbydefault=false"
|
- --providers.docker.exposedbydefault=false
|
||||||
- "--entrypoints.websecure.address=:443"
|
- --entrypoints.websecure.address=:443
|
||||||
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
|
- --certificatesresolvers.myresolver.acme.tlschallenge=true
|
||||||
- "--certificatesresolvers.myresolver.acme.email=${supportEmail}"
|
- --certificatesresolvers.myresolver.acme.email=${supportEmail}
|
||||||
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
|
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- 80:80
|
||||||
- "443:443"
|
- 443:443
|
||||||
volumes:
|
volumes:
|
||||||
- "./letsencrypt:/letsencrypt"
|
- ./letsencrypt:/letsencrypt
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
app-network:
|
app-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const dockerfile = `
|
const dockerfile = `
|
||||||
FROM node:21-bookworm-slim
|
FROM node:22-bookworm-slim
|
||||||
WORKDIR "/app"
|
WORKDIR "/app"
|
||||||
COPY package*.json /app
|
COPY package*.json /app
|
||||||
RUN npm install --production
|
RUN npm install --omit=dev
|
||||||
COPY . /app
|
COPY . /app
|
||||||
EXPOSE ${appPort}
|
EXPOSE ${appPort}
|
||||||
USER node
|
USER node
|
||||||
|
|||||||
Generated
+709
-1597
File diff suppressed because it is too large
Load Diff
+9
-9
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "news-server",
|
"name": "news-server",
|
||||||
"version": "1.7.0",
|
"version": "1.7.5",
|
||||||
"description": "An API centric news server. Uses Sequelize and mariaDB by default.",
|
"description": "An API centric news server. Uses Sequelize and mariaDB by default.",
|
||||||
"main": "server/server.js",
|
"main": "server/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -13,21 +13,21 @@
|
|||||||
"url": "git+https://github.com/krgamestudios/news-server.git"
|
"url": "git+https://github.com/krgamestudios/news-server.git"
|
||||||
},
|
},
|
||||||
"author": "Kayne Ruse",
|
"author": "Kayne Ruse",
|
||||||
"license": "ISC",
|
"license": "Zlib",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/krgamestudios/news-server/issues"
|
"url": "https://github.com/krgamestudios/news-server/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/krgamestudios/news-server#readme",
|
"homepage": "https://github.com/krgamestudios/news-server#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^17.2.3",
|
||||||
"express": "^4.18.2",
|
"express": "^5.2.1",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.3",
|
||||||
"mariadb": "^3.2.3",
|
"mariadb": "^3.4.5",
|
||||||
"markdown-it": "^13.0.2",
|
"markdown-it": "^14.1.0",
|
||||||
"sequelize": "^6.35.2"
|
"sequelize": "^6.37.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^3.0.2"
|
"nodemon": "^3.1.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const Sequelize = require('sequelize');
|
|||||||
|
|
||||||
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
|
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
|
||||||
host: process.env.DB_HOSTNAME,
|
host: process.env.DB_HOSTNAME,
|
||||||
|
port: process.env.DB_PORTNAME,
|
||||||
dialect: 'mariadb',
|
dialect: 'mariadb',
|
||||||
timezone: process.env.DB_TIMEZONE,
|
timezone: process.env.DB_TIMEZONE,
|
||||||
logging: process.env.DB_LOGGING ? console.log : false
|
logging: process.env.DB_LOGGING ? console.log : false
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ const edit = require('./edit');
|
|||||||
const remove = require('./remove');
|
const remove = require('./remove');
|
||||||
|
|
||||||
//basic route management (all query possibilities)
|
//basic route management (all query possibilities)
|
||||||
router.get('/:id(\\d+)?', cors(), query(false, false));
|
router.get('/{:id}', cors(), query(false, false));
|
||||||
router.get('/archive/:id(\\d+)?', cors(), query(true, false));
|
router.get('/archive/{:id}', cors(), query(true, false));
|
||||||
router.get('/metadata/:id(\\d+)?', cors(), query(false, true));
|
router.get('/metadata/{:id}', cors(), query(false, true));
|
||||||
router.get('/archive/metadata/:id(\\d+)?', cors(), query(true, true));
|
router.get('/archive/metadata/{:id}', cors(), query(true, true));
|
||||||
|
|
||||||
//use middleware to authenticate the rest of the routes
|
//use middleware to authenticate the rest of the routes
|
||||||
router.use(cors({
|
router.use(cors({
|
||||||
@@ -37,7 +37,7 @@ router.use((req, res, next) => {
|
|||||||
|
|
||||||
//authenticated routes
|
//authenticated routes
|
||||||
router.post('/', publish);
|
router.post('/', publish);
|
||||||
router.patch('/:id(\\d+)', edit);
|
router.patch('/{:id}', edit);
|
||||||
router.delete('/:id(\\d+)', remove);
|
router.delete('/{:id}', remove);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,7 @@ const database = require('./database');
|
|||||||
app.use('/news', require('./news'));
|
app.use('/news', require('./news'));
|
||||||
|
|
||||||
//error on access
|
//error on access
|
||||||
app.get('*', (req, res) => {
|
app.get('/{*any}', (req, res) => {
|
||||||
res.redirect('https://github.com/krgamestudios/news-server');
|
res.redirect('https://github.com/krgamestudios/news-server');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -24,4 +24,5 @@ app.get('*', (req, res) => {
|
|||||||
server.listen(process.env.WEB_PORT || 3100, async (err) => {
|
server.listen(process.env.WEB_PORT || 3100, async (err) => {
|
||||||
await database.sync();
|
await database.sync();
|
||||||
console.log(`listening to localhost:${process.env.WEB_PORT || 3100}`);
|
console.log(`listening to localhost:${process.env.WEB_PORT || 3100}`);
|
||||||
|
console.log(`database located at ${process.env.DB_HOSTNAME || '<default>'}:${process.env.DB_PORTNAME || '<default>'}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#use this while debugging
|
#use this while debugging
|
||||||
CREATE DATABASE IF NOT EXISTS news;
|
CREATE DATABASE news;
|
||||||
CREATE USER IF NOT EXISTS 'news'@'%' IDENTIFIED BY 'venusaur';
|
CREATE USER 'news'@'%' IDENTIFIED BY 'venusaur';
|
||||||
GRANT ALL PRIVILEGES ON news.* TO 'news'@'%';
|
GRANT ALL PRIVILEGES ON news.* TO 'news'@'%';
|
||||||
|
|||||||
Reference in New Issue
Block a user