Compare commits

..

28 Commits

Author SHA1 Message Date
dependabot[bot] 7a90ea863b Bump dotenv from 17.4.1 to 17.4.2
Bumps [dotenv](https://github.com/motdotla/dotenv) from 17.4.1 to 17.4.2.
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v17.4.1...v17.4.2)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-version: 17.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-17 08:27:08 +10:00
dependabot[bot] dd87018b8c Bump dotenv from 17.3.1 to 17.4.1
Bumps [dotenv](https://github.com/motdotla/dotenv) from 17.3.1 to 17.4.1.
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v17.3.1...v17.4.1)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-version: 17.4.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-07 22:02:04 +10:00
dependabot[bot] 8680fb8e84 Bump sequelize from 6.37.7 to 6.37.8
Bumps [sequelize](https://github.com/sequelize/sequelize) from 6.37.7 to 6.37.8.
- [Release notes](https://github.com/sequelize/sequelize/releases)
- [Changelog](https://github.com/sequelize/sequelize/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sequelize/sequelize/compare/v6.37.7...v6.37.8)

---
updated-dependencies:
- dependency-name: sequelize
  dependency-version: 6.37.8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-03 08:55:56 +11:00
dependabot[bot] ad5133827f Bump mariadb from 3.5.1 to 3.5.2
Bumps [mariadb](https://github.com/mariadb-corporation/mariadb-connector-nodejs) from 3.5.1 to 3.5.2.
- [Release notes](https://github.com/mariadb-corporation/mariadb-connector-nodejs/releases)
- [Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.5.1...3.5.2)

---
updated-dependencies:
- dependency-name: mariadb
  dependency-version: 3.5.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-03 08:55:41 +11:00
dependabot[bot] 144e2cfc9c Bump mariadb from 3.4.5 to 3.5.1
Bumps [mariadb](https://github.com/mariadb-corporation/mariadb-connector-nodejs) from 3.4.5 to 3.5.1.
- [Release notes](https://github.com/mariadb-corporation/mariadb-connector-nodejs/releases)
- [Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/3.4.5...3.5.1)

---
updated-dependencies:
- dependency-name: mariadb
  dependency-version: 3.5.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-01 09:49:56 +11:00
dependabot[bot] 88477e4b62 Bump nodemon from 3.1.11 to 3.1.14
Bumps [nodemon](https://github.com/remy/nodemon) from 3.1.11 to 3.1.14.
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](https://github.com/remy/nodemon/compare/v3.1.11...v3.1.14)

---
updated-dependencies:
- dependency-name: nodemon
  dependency-version: 3.1.14
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-01 09:47:49 +11:00
dependabot[bot] eb506e7f1b Bump markdown-it from 14.1.0 to 14.1.1
Bumps [markdown-it](https://github.com/markdown-it/markdown-it) from 14.1.0 to 14.1.1.
- [Changelog](https://github.com/markdown-it/markdown-it/blob/master/CHANGELOG.md)
- [Commits](https://github.com/markdown-it/markdown-it/compare/14.1.0...14.1.1)

---
updated-dependencies:
- dependency-name: markdown-it
  dependency-version: 14.1.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-20 09:16:50 +11:00
dependabot[bot] edf12ec40b Bump cors from 2.8.5 to 2.8.6
Bumps [cors](https://github.com/expressjs/cors) from 2.8.5 to 2.8.6.
- [Release notes](https://github.com/expressjs/cors/releases)
- [Changelog](https://github.com/expressjs/cors/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/cors/compare/v2.8.5...v2.8.6)

---
updated-dependencies:
- dependency-name: cors
  dependency-version: 2.8.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-20 09:16:02 +11:00
dependabot[bot] 1a353a85ce Bump dotenv from 17.2.3 to 17.3.1
Bumps [dotenv](https://github.com/motdotla/dotenv) from 17.2.3 to 17.3.1.
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v17.2.3...v17.3.1)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-version: 17.3.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-20 09:11:28 +11:00
Kayne Ruse cee4ea98f5 Version bump 2025-12-10 11:52:21 +11:00
Kayne Ruse cdafc4bd79 Updated syntax for docker and CI files 2025-12-10 10:18:38 +11:00
Kayne Ruse a9485a4d0a Updated dependencies 2025-12-10 09:08:18 +11:00
dependabot[bot] d0877dd0a9 Bump nodemon from 3.1.10 to 3.1.11
Bumps [nodemon](https://github.com/remy/nodemon) from 3.1.10 to 3.1.11.
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](https://github.com/remy/nodemon/compare/v3.1.10...v3.1.11)

---
updated-dependencies:
- dependency-name: nodemon
  dependency-version: 3.1.11
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-19 23:03:21 +11:00
dependabot[bot] bad631eeae Bump dotenv from 17.2.2 to 17.2.3
Bumps [dotenv](https://github.com/motdotla/dotenv) from 17.2.2 to 17.2.3.
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v17.2.2...v17.2.3)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-version: 17.2.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-12 22:24:03 +11:00
Kayne Ruse 5915ae2733 Updated dependencies 2025-09-18 10:41:32 +10:00
Kayne Ruse ab7047b9cd Bump dependencies 2025-09-10 14:05:58 +10:00
dependabot[bot] 23f87d376a Bump dotenv from 17.2.1 to 17.2.2
Bumps [dotenv](https://github.com/motdotla/dotenv) from 17.2.1 to 17.2.2.
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v17.2.1...v17.2.2)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-version: 17.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-10 12:59:11 +10:00
Kayne Ruse ffe9b66886 Experimenting with dependabot 2025-09-09 18:55:55 +10:00
Kayne Ruse c85b689aed Updated dependencies 2025-07-26 03:58:38 +10:00
Ratstail91 22735a9ea6 Fully tested the remote database
Updated the base docker image
2024-05-03 09:28:39 +10:00
Ratstail91 9367999ef2 UNTESTED: Updated all dependencies 2024-05-03 07:08:29 +10:00
Ratstail91 d42824d41a UNTESTED: Added database port as a configurable option
Also updated license field in package.json
2024-04-15 21:03:08 +10:00
Ratstail91 7d2186860c Updated dependencies 2024-04-15 17:12:18 +10:00
Ratstail91 99dfaddf04 Updated libraries, docker engine version, docker distro version
This also officially publishes the changes from @eels.
Sorry it took so long.
2023-12-23 23:36:18 +11:00
Kayne Ruse 45b9ac1281 Merge pull request #9 from eels/feature/additional-query-features
feat: resolve long-standing issues + fix minor bugs + update docs
2023-08-30 23:40:52 +10:00
Liam Howell 8d0d804923 docs: fix spelling 2023-08-30 13:37:31 +01:00
Liam Howell fe91ce6ed3 feat: add ability to paginate results, add ability to retrieve certain fields, fix docker-compose output, update docs 2023-08-30 13:19:45 +01:00
Kayne Ruse a6c627a178 Docker behaviour changed, fixed 2023-06-26 23:18:42 +10:00
15 changed files with 1177 additions and 762 deletions
+4 -2
View File
@@ -2,7 +2,9 @@ WEB_PORT=3100
WEB_ORIGIN=http://localhost:3001
DB_HOSTNAME=database
DB_HOSTNAME=localhost
DB_PORTNAME=3306
DB_DATABASE=news
DB_USERNAME=news
DB_PASSWORD=venusaur
@@ -17,4 +19,4 @@ DB_LOGGING=
SECRET_ACCESS=access
# Select the default number of articles returned by a GET request
QUERY_LIMIT=10
PAGE_SIZE=10
+10
View File
@@ -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"
+9 -7
View File
@@ -5,19 +5,21 @@ on:
push:
tags:
- v1.*
workflow_dispatch:
jobs:
push_to_registry:
name: Push Docker Image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check Out The Repo
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Get Smart Tag
id: prepare
@@ -26,13 +28,13 @@ jobs:
docker_image: krgamestudios/news-server
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.prepare.outputs.tag }}
+3 -3
View File
@@ -1,8 +1,8 @@
FROM node:18-bullseye-slim
FROM node:22-bookworm-slim
WORKDIR "/app"
COPY package*.json ./
RUN npm install --production
COPY package*.json /app
RUN npm install --omit=dev
COPY . /app
EXPOSE 3100
USER node
+230 -94
View File
@@ -6,7 +6,7 @@ This server is available via docker hub at krgamestudios/news-server.
# 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):
@@ -22,112 +22,248 @@ Content-Type: application/json
# API
### `GET /news/:id?`
Get either an array of articles (newest first), or a specified article if the optional "id" parameter is given.
#### Response Body
```jsonc
[{
// [Number] index of the article
"index": index,
// [String] author of the article
"author": author,
// [String] raw body of the article
"body": body,
// [Number] number of times this article has been edited
"edits": edits,
// [String] body of the article rendered as HTML
"rendered": rendered,
// [String] title of the article
"title": title,
// [Date] time article was created
"createdAt": createdAt,
// [Date] time article was updated
"updatedAt": updatedAt,
}]
```
//NOTE: GET will return an empty array if a specific article can't be found
//NOTE: you can add a "limit" query parameter to change the default limit
GET /news?limit=10
#### Available Query Parameters
###
- `fields`
- TYPE: `string`
A comma separated list of the field names you want returning, (index will always be returned)
- `page`
- TYPE: `number`
The current page you want returning
- `page_size`
- TYPE: `number`
The number of results to return. This superseeds the `PAGE_SIZE` environment variable for the query
> **NOTE**
> If a specific article is requested, then just that article is returned rather than an array
//DOCS: get latest news, up to a default limit, or specify the index "id"
GET /news/:id
### `GET /news/archive/:id?`
Get either an array of articles (oldest first), or a specified article if the optional "id" parameter is given.
###
#### Response Body
```jsonc
[{
// [Number] index of the article
"index": index,
//DOCS: get the news starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/:id
// [String] author of the article
"author": author,
//DOCS: result (if only a single article is specified, returns just that article rather than an array):
[
{
"index": index, //absolute index of the result
"title": title, //title of the article
"author": author, //author of the aricle
"body": body, //body of the article
"rendered": rendered //body rendered as HTML
"edits": edits //number of times this article has been edited
"createdAt": createdAt //time created
"updatedAt": updatedAt //time updated
},
...
]
// [String] raw body of the article
"body": body,
// [Number] number of times this article has been edited
"edits": edits,
###
// [String] body of the article rendered as HTML
"rendered": rendered,
// [String] title of the article
"title": title,
//DOCS: get the latest metadata, up to a default limit, or specify the index "id"
GET /news/metadata/:id
// [Date] time article was created
"createdAt": createdAt,
###
//DOCS: get the metadata starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/metadata/:id
//DOCS: result (if only a single article is specified, returns just that article rather than an array):
[
{
"index": index, //absolute index of the result
"title": title, //title of the article
"author": author //author of the article
"edits": edits //number of times this article has been edited
"createdAt": createdAt //time created
"updatedAt": updatedAt //time updated
},
...
]
###
//DOCS: send a formatted JSON object, returns new index on success, or error on failure
POST /news
Authorization: Bearer XXX
{
"title": title //title of the article
"author": author //author of the article
"body": body //body of the article
}
//DOCS: result (status 200 on success, otherwise an error status):
{
"index": index //new index of the article
}
###
//DOCS: similar to `POST /news`, but allows overwriting an existing article
PATCH /news/:id
Authorization: Bearer XXX
{
"title": title //title of the article, optional
"author": author //author of the article, optional
"body": body //body of the article, optional
}
//DOCS: result: status 200 on success, otherwise an error status
###
//DOCS: remove an article from the news feed
DELETE /news/:id
Authorization: Bearer XXX
//DOCS: result: status 200 on success, otherwise an error status
###
// [Date] time article was updated
"updatedAt": updatedAt,
}]
```
#### Available Query Parameters
- `fields`
- TYPE: `string`
A comma separated list of the field names you want returning, (index will always be returned)
- `page`
- TYPE: `number`
The current page you want returning
- `page_size`
- TYPE: `number`
The number of results to return. This superseeds the `PAGE_SIZE` environment variable for the query
> **NOTE**
> If a specific article is requested, then just that article is returned rather than an array
### `GET /news/metadata/:id?`
Get either an array of metadata (newest first), or a specified article's metadata if the optional "id" parameter is given.
#### Response Body
```jsonc
[{
// [Number] index of the article
"index": index,
// [String] author of the article
"author": author,
// [Number] number of times this article has been edited
"edits": edits,
// [String] title of the article
"title": title,
// [Date] time article was created
"createdAt": createdAt,
// [Date] time article was updated
"updatedAt": updatedAt,
}]
```
#### Available Query Parameters
- `fields`
- TYPE: `string`
A comma separated list of the field names you want returning, (index will always be returned)
- `page`
- TYPE: `number`
The current page you want returning
- `page_size`
- TYPE: `number`
The number of results to return. This superseeds the `PAGE_SIZE` environment variable for the query
> **NOTE**
> If a specific article is requested, then just that article is returned rather than an array
### `GET /news/archive/metadata/:id?`
Get either an array of metadata (oldest first), or a specified article's metadata if the optional "id" parameter is given.
#### Response Body
```jsonc
[{
// [Number] index of the article
"index": index,
// [String] author of the article
"author": author,
// [Number] number of times this article has been edited
"edits": edits,
// [String] title of the article
"title": title,
// [Date] time article was created
"createdAt": createdAt,
// [Date] time article was updated
"updatedAt": updatedAt,
}]
```
#### Available Query Parameters
- `fields`
- TYPE: `string`
A comma separated list of the field names you want returning, (index will always be returned)
- `page`
- TYPE: `number`
The current page you want returning
- `page_size`
- TYPE: `number`
The number of results to return. This supersedes the `PAGE_SIZE` environment variable for the query
> **NOTE**
> If a specific article is requested, then just that article is returned rather than an array
---
### `POST /news`
> **IMPORTANT**
> Requires valid JWT Authorization header (Authorization: Bearer XXX)
Create a new article resource, returns either the new article's index on success, or an error on failure.
#### Request Body
```jsonc
{
// [String] OPTIONAL: title of the article
"title": title,
// [String] OPTIONAL: author of the article
"author": author,
// [String] OPTIONAL: body of the article
"body": body,
}
```
#### Response Body
```jsonc
{
// [Number]: new index of the article
"index": index,
}
```
### `PATCH /news/:id`
> **IMPORTANT**
> Requires valid JWT Authorization header (Authorization: Bearer XXX)
Update an existing article resource, returns either status code 200 on success, or an error status on failure.
#### Request Body
```jsonc
{
// [String] OPTIONAL: title of the article
"title": title,
// [String] OPTIONAL: author of the article
"author": author,
// [String] OPTIONAL: body of the article
"body": body,
}
```
### `DELETE /news/:id`
> **IMPORTANT**
> Requires valid JWT Authorization header (Authorization: Bearer XXX)
Remove an existing article resource from the news feed, returns either status code 200 on success, or an error status on failure.
+55 -30
View File
@@ -33,6 +33,25 @@ const question = (prompt, def = null) => {
const appWebOrigin = await question('Web Origin', `https://example.com`); //TODO: clean these up properly
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 appDBPass = await question('DB Pass', 'venusaur');
const dbRootPass = await question('DB Root Pass');
@@ -43,39 +62,43 @@ const question = (prompt, def = null) => {
//generate the files
const ymlfile = `
version: '3'
services:
${appName}:
build:
context: .
ports:
- "${appPort}"
- ${appPort}
labels:
- "traefik.enable=true"
- "traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)"
- "traefik.http.routers.${appName}router.entrypoints=websecure"
- "traefik.http.routers.${appName}router.tls.certresolver=myresolver"
- "traefik.http.routers.${appName}router.service=${appName}service@docker"
- "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}"
- traefik.enable=true
- traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)
- traefik.http.routers.${appName}router.entrypoints=websecure
- traefik.http.routers.${appName}router.tls.certresolver=myresolver
- traefik.http.routers.${appName}router.service=${appName}service@docker
- traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}
environment:
- WEB_PORT=${appPort}
- WEB_ORIGIN=${appWebOrigin}
- DB_HOSTNAME=database
- DB_HOSTNAME=${appDBHost}
- DB_PORTNAME=${appDBPort}
- DB_DATABASE=${appName}
- DB_USERNAME=${appDBUser}
- DB_PASSWORD=${appDBPass}
- DB_TIMEZONE=Australia/Sydney
- QUERY_LIMIT=10
- PAGE_SIZE=10
- SECRET_ACCESS=${appSecretAccess}
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
networks:
- app-network
- app-network${ appDBHost != 'database' ? '' : `
depends_on:
- database
database:
image: mariadb:latest
environment:
MYSQL_DATABASE: ${appName}
MYSQL_TCP_PORT: ${appDBPort}
MYSQL_USER: ${appDBUser}
MYSQL_PASSWORD: ${appDBPass}
MYSQL_ROOT_PASSWORD: ${dbRootPass}
@@ -84,37 +107,39 @@ services:
volumes:
- ./mysql:/var/lib/mysql
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro`}
traefik_${appName}:
container_name: ${appName}_traefik
image: "traefik:v2.4"
container_name: "traefik"
image: traefik:latest
command:
- "--log.level=ERROR"
- "--api.insecure=false"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.email=${supportEmail}"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
- --log.level=ERROR
- --api.insecure=false
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.websecure.address=:443
- --certificatesresolvers.myresolver.acme.tlschallenge=true
- --certificatesresolvers.myresolver.acme.email=${supportEmail}
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
ports:
- "80:80"
- "443:443"
- 80:80
- 443:443
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./letsencrypt:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- app-network
networks:
app-network:
driver: bridge
`;
const dockerfile = `
FROM node:18-bullseye-slim
FROM node:22-bookworm-slim
WORKDIR "/app"
COPY package*.json ./
RUN npm install --production
COPY package*.json /app
RUN npm install --omit=dev
COPY . /app
EXPOSE ${appPort}
USER node
+804 -532
View File
File diff suppressed because it is too large Load Diff
+10 -13
View File
@@ -1,6 +1,6 @@
{
"name": "news-server",
"version": "1.6.4",
"version": "1.7.5",
"description": "An API centric news server. Uses Sequelize and mariaDB by default.",
"main": "server/server.js",
"scripts": {
@@ -13,24 +13,21 @@
"url": "git+https://github.com/krgamestudios/news-server.git"
},
"author": "Kayne Ruse",
"license": "ISC",
"license": "Zlib",
"bugs": {
"url": "https://github.com/krgamestudios/news-server/issues"
},
"homepage": "https://github.com/krgamestudios/news-server#readme",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"mariadb": "^3.2.0",
"markdown-it": "^13.0.1",
"sequelize": "^6.32.1"
"cors": "^2.8.6",
"dotenv": "^17.4.2",
"express": "^5.2.1",
"jsonwebtoken": "^9.0.3",
"mariadb": "^3.5.2",
"markdown-it": "^14.1.1",
"sequelize": "^6.37.8"
},
"devDependencies": {
"nodemon": "^2.0.22"
},
"overrides": {
"semver": "^7.5.2"
"nodemon": "^3.1.14"
}
}
+1
View File
@@ -2,6 +2,7 @@ const Sequelize = require('sequelize');
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
host: process.env.DB_HOSTNAME,
port: process.env.DB_PORTNAME,
dialect: 'mariadb',
timezone: process.env.DB_TIMEZONE,
logging: process.env.DB_LOGGING ? console.log : false
+6 -10
View File
@@ -12,14 +12,10 @@ const edit = require('./edit');
const remove = require('./remove');
//basic route management (all query possibilities)
router.get('/', cors(), query(false, false));
router.get('/:id(\\d+)', cors(), query(false, false));
router.get('/archive', cors(), query(true, false));
router.get('/archive/:id(\\d+)', cors(), query(true, false));
router.get('/metadata', cors(), query(false, true));
router.get('/metadata/:id(\\d+)', cors(), query(false, true));
router.get('/archive/metadata', cors(), query(true, true));
router.get('/archive/metadata/:id(\\d+)', cors(), query(true, true));
router.get('/{:id}', cors(), query(false, false));
router.get('/archive/{:id}', cors(), query(true, false));
router.get('/metadata/{:id}', cors(), query(false, true));
router.get('/archive/metadata/{:id}', cors(), query(true, true));
//use middleware to authenticate the rest of the routes
router.use(cors({
@@ -41,7 +37,7 @@ router.use((req, res, next) => {
//authenticated routes
router.post('/', publish);
router.patch('/:id(\\d+)', edit);
router.delete('/:id(\\d+)', remove);
router.patch('/{:id}', edit);
router.delete('/{:id}', remove);
module.exports = router;
+41 -14
View File
@@ -1,18 +1,45 @@
const { Op } = require('sequelize');
const { articles } = require('../database/models');
//the query function that can be reused
const query = (ascending, metadataOnly) => async (req, res) => {
if (process.env.QUERY_LIMIT) {
process.env.PAGE_SIZE = process.env.QUERY_LIMIT;
console.warn('The use of QUERY_LIMIT is deprecated. Please use PAGE_SIZE instead.');
}
if (req.query.limit) {
req.query.page_size = req.query.limit;
console.warn('The use of the limit parameter is deprecated. Please use page_size instead.');
}
const PAGE_SIZE = parseInt(req.query.page_size) || parseInt(process.env.PAGE_SIZE) || 999;
const PAGE = parseInt(req.query.page) || 1;
const ARTICLE_ID = req.params.id ? parseInt(req.params.id) : undefined;
const FIELDS = req.query.fields ? req.query.fields.split(',') : undefined;
const attributes = [
'index',
'author',
'createdAt',
'edits',
'title',
'updatedAt',
].concat(metadataOnly ? [] : [
'body',
'rendered'
]);
//filter out attributes that aren't requested
const attributesToFetch = FIELDS ? attributes.filter((attr) => {
return FIELDS.includes(attr) || attr === 'index';
}) : attributes;
//specific search (id is defined)
if (req.params.id && typeof(parseInt(req.params.id)) === 'number') {
if (typeof(ARTICLE_ID) === 'number' && !isNaN(ARTICLE_ID)) {
const result = await articles.findOne({
attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
],
attributes: attributesToFetch,
where: {
index: {
[Op.eq]: ascending ? parseInt(req.params.id) : (await articles.max('index')) - parseInt(req.params.id) + 1
}
index: ascending ? ARTICLE_ID : (await articles.max('index') - ARTICLE_ID) + 1,
}
});
@@ -23,16 +50,16 @@ const query = (ascending, metadataOnly) => async (req, res) => {
//default search
else {
const result = await articles.findAndCountAll({
attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
],
attributes: attributesToFetch,
limit: PAGE_SIZE,
offset: Math.max((PAGE - 1) * PAGE_SIZE, 0),
order: [
['index', ascending ? 'ASC' : 'DESC']
],
limit: parseInt(req.query.limit) || parseInt(process.env.QUERY_LIMIT) || 999
]
});
return res.status(200).json(result.rows || result);
//result is empty array if failed to find
return res.status(200).json(result.rows || result || []);
}
};
+2 -45
View File
@@ -16,7 +16,7 @@ const database = require('./database');
app.use('/news', require('./news'));
//error on access
app.get('*', (req, res) => {
app.get('/{*any}', (req, res) => {
res.redirect('https://github.com/krgamestudios/news-server');
});
@@ -24,48 +24,5 @@ app.get('*', (req, res) => {
server.listen(process.env.WEB_PORT || 3100, async (err) => {
await database.sync();
console.log(`listening to localhost:${process.env.WEB_PORT || 3100}`);
//COMPATABILITY: parse the unrendered data from the database
const markdownIt = require('markdown-it')();
const { articles, revisions } = require('./database/models');
const missingArticles = await articles.findAll({
where: {
rendered: ''
}
});
const missingRevisions = await revisions.findAll({
where: {
rendered: ''
}
});
await Promise.all(
missingArticles.map(async ma => {
ma.update({
rendered: markdownIt.render(ma.body)
}, {
where: {
index: ma.index
}
});
})
)
.then(result => {if (result.length > 0) console.log('Rendered articles in HTML'); })
;
await Promise.all(
missingRevisions.map(async mr => {
mr.update({
rendered: markdownIt.render(mr.body)
}, {
where: {
index: mr.index
}
});
})
)
.then(result => {if (result.length > 0) console.log('Rendered revisions in HTML'); })
;
console.log(`database located at ${process.env.DB_HOSTNAME || '<default>'}:${process.env.DB_PORTNAME || '<default>'}`);
});
+2 -2
View File
@@ -1,4 +1,4 @@
#use this while debugging
CREATE DATABASE IF NOT EXISTS news;
CREATE USER IF NOT EXISTS 'news'@'%' IDENTIFIED BY 'venusaur';
CREATE DATABASE news;
CREATE USER 'news'@'%' IDENTIFIED BY 'venusaur';
GRANT ALL PRIVILEGES ON news.* TO 'news'@'%';
-6
View File
@@ -1,6 +0,0 @@
use news;
ALTER TABLE revisions CHANGE COLUMN id `index` INTEGER(11) UNIQUE NOT NULL AUTO_INCREMENT;
ALTER TABLE revisions DROP FOREIGN KEY revisions_ibfk_1;
ALTER TABLE revisions CHANGE COLUMN originalIndex originalIndex INTEGER(11);
-4
View File
@@ -1,4 +0,0 @@
ALTER TABLE articles ADD COLUMN rendered TEXT DEFAULT "" AFTER body;
ALTER TABLE revisions ADD COLUMN rendered TEXT DEFAULT "" AFTER body;