Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions strapi/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HOST=0.0.0.0
PORT=1337
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified
JWT_SECRET=tobemodified

PUBLIC_KEY = <YOUR_IMAGEKIT_PUBLIC_KEY>
URL_ENDPOINT = <YOUR_IMAGEKIT_URL_ENDPOINT>
PRIVATE_KEY = <YOUR_IMAGEKIT_PRIVATE_KEY>
131 changes: 131 additions & 0 deletions strapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
############################
# OS X
############################

.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite
*.sqlite3


############################
# Misc.
############################

*#
ssl
.idea
nbproject
public/uploads/*
!public/uploads/.gitkeep
.tsbuildinfo
.eslintcache

############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
node_modules
.node_history

############################
# Package managers
############################

.yarn/*
!.yarn/cache
!.yarn/unplugged
!.yarn/patches
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*
yarn-error.log

############################
# Tests
############################

coverage

############################
# Strapi
############################

.env
license.txt
exports
.strapi
dist
build
.strapi-updater.json
.strapi-cloud.json
150 changes: 150 additions & 0 deletions strapi/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

# How to run locally

This project is developed using node version 18.

## Setup environment variables

Create a `.env`, file and add below parameters:

```js
# Server
HOST=0.0.0.0
PORT=1337

# Secrets
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified

# Database
DATABASE_CLIENT=sqlite
DATABASE_HOST=
DATABASE_PORT=
DATABASE_NAME=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_SSL=false
DATABASE_FILENAME=.tmp/data.db
JWT_SECRET=tobemodified

PUBLIC_KEY = <YOUR_IMAGEKIT_PUBLIC_KEY>
URL_ENDPOINT = <YOUR_IMAGEKIT_URL_ENDPOINT>
PRIVATE_KEY = <YOUR_IMAGEKIT_PRIVATE_KEY>
```

You can get the value of [URL_ENDPOINT](https://imagekit.io/dashboard/url-endpoints) from your ImageKit dashboard.
`PUBLIC_KEY` and `PRIVATE_KEY` can be obtained from the [developer](https://imagekit.io/dashboard/developer/api-keys) section in your ImageKit dashboard.


### Install packages:

```bash
npm install
```

### Run the app

```
npm run develop
```

The app will run at `http://localhost:1337/admin`, and it will ask you to register as the first local administrator. Once done, You now have access to the admin panel.

## Configuration

To make our provider work, we need to add a configuration in the `./config/plugins.js` file. The configuration should include the following parameters, as described below.

- `provider`: Specifies the name of the provider.
- `providerOptions`: Contains the options required to configure the provider.
* `urlEndpoint`: A required parameter that can be obtained from the [URL-endpoint section](https://imagekit.io/dashboard/url-endpoints) or the [developer section](https://imagekit.io/dashboard/developer/api-keys) on your ImageKit dashboard.
* `publicKey` and `privateKey`: Required parameters that can be retrieved from the [developer section](https://imagekit.io/dashboard/developer/api-keys) on your ImageKit dashboard.
* `uploadOptions` is an optional parameter that accepts upload parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload). The following parameters are supported by the provider: `folder`, `useUniqueFileName`, `tags`, `checks`, `isPrivateFile`, `customCoordinates`, `webhookUrl`, `extensions`, `transformation`, and `customMetadata`.

For more information about using a provider, refer to the [documentation about using a provider](https://docs.strapi.io/dev-docs/providers). To understand how environment variables are used in Strapi, please refer to the [documentation about environment variables](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment).

### Provider Configuration

Below is an example of how to configure the provider in `./config/plugins.js`.

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: "strapi-provider-upload-imagekitio",
providerOptions: {
publicKey: env("PUBLIC_KEY"),
privateKey: env("PRIVATE_KEY"),
urlEndpoint: env("URL_ENDPOINT"),

// Optional
uploadOptions: {
folder: "/path",
useUniqueFileName: true,
tags: ["tag1", "tag2"],
checks: `"file.size" < "1mb"`,
isPrivateFile: false,
customCoordinates: "1,2,3,4",
webhookUrl: "https://testwebook.com",
extensions: [
{
name: "google-auto-tagging",
maxTags: 5,
minConfidence: 95,
},
],
transformation: {
pre: "l-text,i-Imagekit,fs-50,l-end",
post: [
{
type: "transformation",
value: "l-text,i-Imagekit,fs-50,l-end",
},
],
},
customMetadata: { test: "value" },
},
},
},
},
// ...
});
```

**Note**: Ensure that the custom metadata `test` is already created in the [Media Library Settings](https://imagekit.io/dashboard/settings/media-library).

### Security Middleware Configuration

The default settings in Strapi's Security Middleware require modifications to the `contentSecurityPolicy` settings to ensure thumbnail previews are visible in the Media Library. Replace the `strapi::security` string with the object provided below, as detailed in the [middleware configuration documentation](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.html#loading-order).

`./config/middlewares.js`

```js
module.exports = [
// ...
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'ik.imagekit.io'],
'media-src': ["'self'", 'data:', 'blob:', 'ik.imagekit.io'],
upgradeInsecureRequests: null,
},
},
},
},
// ...
];
```

# Useful links
* ImageKit Strapi provider quickstart guide - https://imagekit.io/docs/integration/strapi
* ImageKit Strapi provider and documentation - https://github.com/imagekit-developer/strapi-provider-upload-imagekitio

# Report a bug
If something doesn't work as expected, report a bug at [email protected].
17 changes: 17 additions & 0 deletions strapi/config/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default ({ env }) => ({
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
apiToken: {
salt: env('API_TOKEN_SALT'),
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT'),
},
},
flags: {
nps: env.bool('FLAG_NPS', true),
promoteEE: env.bool('FLAG_PROMOTE_EE', true),
},
});
7 changes: 7 additions & 0 deletions strapi/config/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
rest: {
defaultLimit: 25,
maxLimit: 100,
withCount: true,
},
};
60 changes: 60 additions & 0 deletions strapi/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import path from 'path';

export default ({ env }) => {
const client = env('DATABASE_CLIENT', 'sqlite');

const connections = {
mysql: {
connection: {
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
sqlite: {
connection: {
filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', '.tmp/data.db')),
},
useNullAsDefault: true,
},
};

return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
},
};
};
Loading