Skip to content

Commit

Permalink
ready to production
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham-yusuf committed Jun 1, 2022
1 parent c891f39 commit 1012bfa
Show file tree
Hide file tree
Showing 8 changed files with 2,017 additions and 1,488 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
HOST=0.0.0.0
PORT=1337
CLOUDINARY_KEY=
CLOUDINARY_NAME=
CLOUDINARY_SECRET=
DATABASE_URL=
ADMIN_JWT_SECRET=
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# Web3ID API

### Running locally

Create a folder and `git clone` from this repository.

Install the dependencies and start the dev server.

```bash
yarn install
yarn develop
```

The strapi server will run on [http://localhost:1337](http://localhost:1337)

Go to the admin panel [(http://localhost:1337/admin)](http://localhost:1337), create an account and start adding sample content.

### Deployment

First, you'll need a [Cloudinary](https://cloudinary.com) and a [Heroku](https://www.heroku.com/) account.

1. From your copy of the repo click the "Deploy to Heroku" button

<a href="https://www.heroku.com/deploy/?template=https://github.com/edgarlr/magazine-api">
<img src="https://assets.strapi.io/uploads/Deploy_button_heroku_b1043fc67d.png" />
</a>

2. Fill the Cloudinary ENV variables.
3. Deploy
4. Once is deployed, go to the admin panel e.g. `https://yourherokudomain.com/admin` and create an account.
5. Last, go to "Setting" > "Users & permissions plugins" > "Public" > "Permissions" and check `find` on Article, Category, Contributor and Pages.

### Adding Content

The recommended flow for adding new content is:

- Add contributor
- Add category
- Add article or page

### Preview Content

Once you have your frontend deployed go to "Settings" > "Preview Content"

Fill it with your info, the URL should look like this.
`https://<yoursite.com>/api/:contentType-preview?secret=<your-secret>&id=:id`

Now, go to any article or page and click on "Preview".

*Note: Preview Content is Optional*
28 changes: 28 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Web3 API",
"description": "API for NFT and Blog",
"keywords": ["strapi", "heroku"],
"repository": "https://github.com/abraham-yusuf/web3-api",
"addons": ["heroku-postgresql:hobby-dev"],
"image": "heroku/nodejs",
"success_url": "/admin",
"env": {
"CLOUDINARY_NAME": {
"description": "Cloud name of your cloudinary account",
"generator": ""
},
"CLOUDINARY_KEY": {
"description": "API Key of your cloudinary account",
"value": ""
},
"CLOUDINARY_SECRET": {
"description": "API Secret of your cloudinary account",
"value": ""
}
},
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
19 changes: 19 additions & 0 deletions config/env/production/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = ({ env }) => ({
defaultConnection: "default",
connections: {
default: {
connector: "bookshelf",
settings: {
client: "postgres",
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "strapi"),
username: env("DATABASE_USERNAME", "strapi"),
password: env("DATABASE_PASSWORD", "strapi"),
schema: "public",
ssl: { rejectUnauthorized: false },
},
options: {},
},
},
});
10 changes: 10 additions & 0 deletions config/env/production/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = ({ env }) => ({
upload: {
provider: "cloudinary",
providerOptions: {
cloud_name: env("CLOUDINARY_NAME"),
api_key: env("CLOUDINARY_KEY"),
api_secret: env("CLOUDINARY_SECRET"),
},
},
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
"strapi": "strapi",
"heroku-prebuild": "node scripts/postgres-env.js"
},
"devDependencies": {},
"dependencies": {
"@strapi/utils": "^4.0.5",
"knex": "0.21.18",
"pg": "^8.7.3",
"sqlite3": "5.0.0",
"strapi": "^3.6.8",
"strapi-admin": "^3.6.8",
Expand All @@ -22,7 +23,8 @@
"strapi-plugin-email": "^3.6.8",
"strapi-plugin-i18n": "^3.6.8",
"strapi-plugin-upload": "^3.6.8",
"strapi-plugin-users-permissions": "^3.6.8"
"strapi-plugin-users-permissions": "^3.6.8",
"strapi-provider-upload-cloudinary": "^3.6.10"
},
"author": {
"name": "Web3ID"
Expand Down
26 changes: 26 additions & 0 deletions scripts/postgres-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
console.log("Start running postgres-env");
const fs = require("fs");

if (process.env.DATABASE_URL) {
const databaseConfig = process.env.DATABASE_URL.split("//")[1];
const [username, passwordAndDb, hostAndPort] = databaseConfig.split(":");
const [password, host] = passwordAndDb.split("@");
const [port, databaseName] = hostAndPort.split("/");
const newLine = "\r\n";
let output = "";

output += `DATABASE_HOST=${host}${newLine}`;
output += `DATABASE_PORT=${port}${newLine}`;
output += `DATABASE_NAME=${databaseName}${newLine}`;
output += `DATABASE_USERNAME=${username}${newLine}`;
output += `DATABASE_PASSWORD=${password}${newLine}`;

fs.writeFile(`./.env`, output, (err) => {
if (err) {
console.warn("create .env file error: ", err);
}
});
console.log(".env file is generated");
}

console.log("Finish running postgres-env");
Loading

0 comments on commit 1012bfa

Please sign in to comment.