Skip to content

Commit 4beaa3c

Browse files
shidilcrcastle
andauthored
Upgrade to strapi v4 (render-examples#13)
* Updated package.json with v4 deps * Updated folder structure to match v4 quickstart * Updated config files for v4 * Bump strapi to 4.1.0 * Use strapi recommended middleware config for cloudinary * Move ADMIN_JWT_SECRET out of code to avoid leaking * Upgrade to 4.1.3 * Remove unnecessary file * Upgrade pg * Upgrade node version * Add placeholder for all env vars * Add APP_KEYS to render.yaml This is required for 4.0.6 and later * Add session middleware required for > v4.0.6 * Re-add setting server.url in production Co-authored-by: Chris Castle <[email protected]>
1 parent 8c688b9 commit 4beaa3c

25 files changed

+4707
-4538
lines changed

.env.example

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
HOST=0.0.0.0
22
PORT=1337
3+
APP_KEYS=testkey
4+
ADMIN_JWT_SECRET=testsecret
5+
API_TOKEN_SALT=testsalt
6+
# The following are only needed in production
7+
# Media is stored on the filesystem in development
8+
#CLOUDINARY_NAME=
9+
#CLOUDINARY_KEY=
10+
#CLOUDINARY_SECRET=

config/admin.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = ({ env }) => ({
2+
auth: {
3+
secret: env('ADMIN_JWT_SECRET'),
4+
},
5+
});

config/api.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
rest: {
3+
defaultLimit: 25,
4+
maxLimit: 100,
5+
withCount: true,
6+
},
7+
};

config/database.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
const path = require('path');
2+
13
module.exports = ({ env }) => ({
2-
defaultConnection: 'default',
3-
connections: {
4-
default: {
5-
connector: 'bookshelf',
6-
settings: {
7-
client: 'sqlite',
8-
filename: env('DATABASE_FILENAME', '.tmp/data.db'),
9-
},
10-
options: {
11-
useNullAsDefault: true,
12-
},
4+
connection: {
5+
client: 'sqlite',
6+
connection: {
7+
filename: path.join(__dirname, '..', env('DATABASE_FILENAME', '.tmp/data.db')),
138
},
9+
useNullAsDefault: true,
1410
},
1511
});

config/env/production/cron-tasks.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/cronjobs.html#creating-a-cron-job
2+
3+
module.exports = {
4+
/**
5+
* Simple example.
6+
* Every monday at 1am.
7+
*/
8+
9+
// '0 0 1 * * 1': ({ strapi }) => {
10+
// // Add your own logic here (e.g. send a queue of email, create a database backup, etc.).
11+
// },
12+
};

config/env/production/database.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ module.exports = ({ env }) => {
44
const { host, port, database, user, password } = parse(env("DATABASE_URL"));
55

66
return {
7-
defaultConnection: "default",
8-
connections: {
9-
default: {
10-
connector: "bookshelf",
11-
settings: {
12-
client: "postgres",
13-
host,
14-
port,
15-
database,
16-
username: user,
17-
password,
18-
},
7+
connection: {
8+
client: "postgres",
9+
connection: {
10+
host,
11+
port,
12+
database,
13+
user,
14+
password
1915
},
16+
debug: false,
2017
},
2118
};
2219
};

config/env/production/logger.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
const { winston } = require("@strapi/logger");
4+
5+
module.exports = {
6+
transports: [
7+
new winston.transports.Console({
8+
level: "error",
9+
}),
10+
],
11+
};

config/env/production/middleware.js

-7
This file was deleted.

config/env/production/middlewares.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = [
2+
"strapi::errors",
3+
{
4+
name: "strapi::security",
5+
config: {
6+
contentSecurityPolicy: {
7+
useDefaults: true,
8+
directives: {
9+
"connect-src": ["'self'", "https:"],
10+
"img-src": ["'self'", "data:", "blob:", "res.cloudinary.com"],
11+
"media-src": ["'self'", "data:", "blob:", "res.cloudinary.com"],
12+
upgradeInsecureRequests: null,
13+
},
14+
},
15+
},
16+
},
17+
"strapi::cors",
18+
"strapi::poweredBy",
19+
"strapi::logger",
20+
"strapi::query",
21+
"strapi::body",
22+
'strapi::session',
23+
"strapi::favicon",
24+
"strapi::public",
25+
];

config/env/production/plugins.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module.exports = ({ env }) => ({
22
upload: {
3-
provider: "cloudinary",
4-
providerOptions: {
5-
cloud_name: env("CLOUDINARY_NAME"),
6-
api_key: env("CLOUDINARY_KEY"),
7-
api_secret: env("CLOUDINARY_SECRET"),
3+
config: {
4+
provider: "cloudinary",
5+
providerOptions: {
6+
cloud_name: env("CLOUDINARY_NAME"),
7+
api_key: env("CLOUDINARY_KEY"),
8+
api_secret: env("CLOUDINARY_SECRET"),
9+
},
810
},
911
},
1012
});

config/env/production/server.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
module.exports = ({ env }) => ({
2-
host: "0.0.0.0",
32
url: env("RENDER_EXTERNAL_URL"),
4-
admin: {
5-
auth: {
6-
secret: env("ADMIN_JWT_SECRET"),
7-
},
8-
},
9-
});
3+
});

config/functions/bootstrap.js

-13
This file was deleted.

config/functions/cron.js

-21
This file was deleted.

config/functions/responses/404.js

-5
This file was deleted.

config/middlewares.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = [
2+
"strapi::errors",
3+
"strapi::security",
4+
"strapi::cors",
5+
"strapi::poweredBy",
6+
"strapi::logger",
7+
"strapi::query",
8+
"strapi::body",
9+
'strapi::session',
10+
"strapi::favicon",
11+
"strapi::public",
12+
];

config/server.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module.exports = ({ env }) => ({
22
host: env('HOST', '0.0.0.0'),
33
port: env.int('PORT', 1337),
4-
admin: {
5-
auth: {
6-
secret: env('ADMIN_JWT_SECRET', 'ea9a418022c8044305a8ab471025ee7b'),
7-
},
4+
app: {
5+
keys: env.array('APP_KEYS')
86
},
97
});

package.json

+7-14
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,13 @@
1111
},
1212
"devDependencies": {},
1313
"dependencies": {
14-
"knex": "<0.20.0",
15-
"pg": "^8.3.3",
16-
"pg-connection-string": "^2.4.0",
17-
"sqlite3": "latest",
18-
"strapi": "3.4.5",
19-
"strapi-admin": "3.4.5",
20-
"strapi-connector-bookshelf": "3.4.5",
21-
"strapi-plugin-content-manager": "3.4.5",
22-
"strapi-plugin-content-type-builder": "3.4.5",
23-
"strapi-plugin-email": "3.4.5",
24-
"strapi-plugin-upload": "3.4.5",
25-
"strapi-plugin-users-permissions": "3.4.5",
26-
"strapi-provider-upload-cloudinary": "3.4.5",
27-
"strapi-utils": "3.4.5"
14+
"@strapi/strapi": "4.1.3",
15+
"@strapi/plugin-users-permissions": "4.1.3",
16+
"@strapi/plugin-i18n": "4.1.3",
17+
"@strapi/provider-upload-cloudinary": "4.1.3",
18+
"pg": "^8.7.0",
19+
"pg-connection-string": "^2.5.0",
20+
"sqlite3": "latest"
2821
},
2922
"author": {
3023
"name": "A Strapi developer"

render.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
healthCheckPath: /_health
99
envVars:
1010
- key: NODE_VERSION
11-
value: 12.18.4
11+
value: ~16.13.0
1212
- key: NODE_ENV
1313
value: production
1414
- key: CLOUDINARY_NAME
@@ -25,6 +25,8 @@ services:
2525
generateValue: true
2626
- key: ADMIN_JWT_SECRET
2727
generateValue: true
28+
- key: APP_KEYS
29+
generateValue: true
2830

2931
databases:
3032
- name: strapi

src/admin/app.example.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default {
2+
config: {
3+
locales: [
4+
// 'ar',
5+
// 'fr',
6+
// 'cs',
7+
// 'de',
8+
// 'dk',
9+
// 'es',
10+
// 'he',
11+
// 'id',
12+
// 'it',
13+
// 'ja',
14+
// 'ko',
15+
// 'ms',
16+
// 'nl',
17+
// 'no',
18+
// 'pl',
19+
// 'pt-BR',
20+
// 'pt',
21+
// 'ru',
22+
// 'sk',
23+
// 'sv',
24+
// 'th',
25+
// 'tr',
26+
// 'uk',
27+
// 'vi',
28+
// 'zh-Hans',
29+
// 'zh',
30+
],
31+
},
32+
bootstrap(app) {
33+
console.log(app);
34+
},
35+
};

src/admin/webpack.config.example.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
/* eslint-disable no-unused-vars */
4+
module.exports = (config, webpack) => {
5+
// Note: we provide webpack above so you should not `require` it
6+
// Perform customizations to webpack config
7+
// Important: return the modified config
8+
return config;
9+
};

api/.gitkeep src/api/.gitkeep

File renamed without changes.
File renamed without changes.

src/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
module.exports = {
4+
/**
5+
* An asynchronous register function that runs before
6+
* your application is initialized.
7+
*
8+
* This gives you an opportunity to extend code.
9+
*/
10+
register(/*{ strapi }*/) {},
11+
12+
/**
13+
* An asynchronous bootstrap function that runs before
14+
* your application gets started.
15+
*
16+
* This gives you an opportunity to set up your data model,
17+
* run jobs, or perform some special logic.
18+
*/
19+
bootstrap(/*{ strapi }*/) {},
20+
};

0 commit comments

Comments
 (0)