# 4731_Oase-news_reel_backend

Backend for the Oase News Reel web application, allows the user to create and manage news articles and provides a REST API for the frontend to consume.\
This project is a [Strapi v4](https://strapi.io/) Instance which is configured to work with a [MYSQL Maria Database hosted @Hostpoint](https://admin.hostpoint.ch/phpmyadmin2/index.php?lang=de&server=mysql25j13.db.hostpoint.internal&db=raumglei_RGnewsReelBackend) (see [Deployment Section](##Deployment)).

Here is a link to the [DEMO NewsFeed FrontEnd](https://data.raumgleiter.com/4731-DEMO/index.html)\
And here the related repository: [REPO NewsFeed FrontEnd](https://git.raumgleiter.com/web/apps/newsfeedfrontend)

The project whas created bootstrapped with [create-strapi-app](https://docs.strapi.io/developer-docs/latest/getting-started/quick-start.html) using the following [Documentation](https://strapi.io/blog/configuring-strapi-mysql-database).

## Usage
**Strapi PROD Admin URL**: https://rgnewsbackend.herokuapp.com/admin\
**Admin Login Credentials**: (see Keepass Entry: `RGNewsFeedAPI ADMIN`)

#### Collections & API Usage
- Articles: Provides fields to represent a news article, associated with a project.
- Projects: Provides fields to represent a project.

#### Postman Collection
- Authentication: Login with admin credentials, see this [Documentation](https://docs.strapi.io/developer-docs/latest/guides/auth-request.html#login-as-a-reader) for Auth Details.
- Articles: Diverse GET Methods with filtering, sorting and pagination.
- Projects: Basic GET Methods.
 

General Strapi API [Documentation](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#complex-filtering)

## Development Requirements

- NPM/YARN
- Node.js
- Git
- Heroku CLI (for Deployment)

## Available Scripts 
### `npm run develop`
Start your Strapi application with autoReload enabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-develop)
Runs the app in the development mode.\
Open http://localhost:1337 to view it in your browser, and add `/admin` to URL to access the admin panel.
The page will reload when you make changes. You may also see any lint errors in the console.



### `npm run start`
Start your Strapi application with autoReload disabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-start)

Runs the app.\

### `npm run build`
Build your admin panel. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-build)
Builds the app for production to the build folder.\
It correctly bundles React in production mode and optimizes the build for the best performance. The build is minified and the filenames include the hashes. Your app is ready to be deployed!.

Add DB Credentials to .env file (see Keepass Entry: `Hostpoint DB RGnewsReelBackend`):
- DATABASE_HOST=
- DATABASE_PORT=
- DATABASE_NAME=
- DATABASE_USERNAME=
- DATABASE_PASSWORD=
- DATABASE_SSL=

## ⚙️ Deployment

Deployment was configured using the following [Guide](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/heroku.html#_4-create-your-heroku-database-config-file-for-production)

### Heroku
- login to heroku (crentials im Keepass login@raum****)
- make sure `.gitignore` includes `package-lock.json`*\
*this reduces app size and prevents conflicts with Heroku
- repository is connected to the heroku app: [rgnewsbackend](https://rgnewsbackend.herokuapp.com/) (`heroku git:remote -a your-heroku-app-name`)
- commit changes to `master` branch
- push changes to heroku with `git push heroku master`
- heroku logs: `heroku logs -a rgnewsbackend`

To see and overview of the RG Apps hosted in Heroku see: [https://dashboard.heroku.com/apps](https://dashboard.heroku.com/apps)\

Add Strapi and DB Credentials to [App Settings](https://dashboard.heroku.com/apps/rgnewsbackend/settings) -> #Config Vars:

- APP_KEYS=
- API_TOKEN_SALT=
- ADMIN_JWT_SECRET=
- JWT_SECRET=
- DATABASE_HOST=
- DATABASE_PORT=
- DATABASE_NAME=
- DATABASE_USERNAME=
- DATABASE_PASSWORD=
- DATABASE_SSL=

### MYSQL Database
DBName: `raumglei_RGnewsReelBackend`
- Mysql DB Hosting [Hostpoint](https://admin.hostpoint.ch/)
- Credentials: in Keepass and (see config/database.js)


### AWS S3 (Image Storage for Media Library)
Strapi Media Library stores by default the contents in local storage. Based on the current hosting solution (heroku free) the dynos are reset and data is lost. We therefore added an extension for the upload plugin [provider](https://www.npmjs.com/package/@strapi/provider-upload-aws-s3) to synchronize data to an AWS S3 Bucket. (see `.config/plugins.js`, and `.config/middleware.js`). The following AWS 
#### Credentials ( AWS S3 User NewsFeed (Keepass) ) 
The following have to be added to an ENV File locally and to Heroku:
- AWS_ACCESS_KEY_ID=
- AWS_ACCESS_SECRET=
- AWS_REGION=
- AWS_BUCKET=

#### AWS ACCESS
Login data: AWS S3 User NewsFeed (Keepass)
IAM: https://us-east-1.console.aws.amazon.com/iam/home#/users/newsfeedreader
Bucket: https://s3.console.aws.amazon.com/s3/buckets/rg-strapiuploadprovider?region=eu-central-1&tab=objects

#### CORS Config
A CORS Configuration is required by the s3 Bucket so that the Application can access the resource:
[REF](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html)

***

## Visuals
Strapi Admin Panel:
![Strapi Admin Panel](documentation/images/example-strapi.png)
DEMO Front End App:
![DEMO Front End App](documentation/images/example-front-end-app.png)

## Roadmap
- [x] Backend Release for Development of UI.
- [ ] Backend Release for Production.

## Project status
Active - The project is actively developed and maintained.

---
