Skip to content

Instantly share code, notes, and snippets.

Avatar

Viktor Andersen viktorfa

View GitHub Profile
@viktorfa
viktorfa / database.js
Last active Aug 17, 2020
Database config for Strapi in Lambda with SQLite
View database.js
// config/database.js
const getDatabaseConfig = ({ env }) => {
if (
env("IS_OFFLINE", null) === "true" ||
env("LAMBDA_RUNTIME_DIR", null) === null
) {
// In local simulated Lambda or normal Strapi
return {
connector: "bookshelf",
View plugins.js
// config/plugins.js
module.exports = ({ env }) => ({
upload: {
provider: "aws-s3",
providerOptions: {
params: {
Bucket: env("BUCKET_NAME"),
},
},
View database.js
// config/database.js
const getDatabaseConfig = ({ env }) => {
if (
env("IS_OFFLINE", null) === "true" ||
env("LAMBDA_RUNTIME_DIR", null) === null
) {
// In local simulated Lambda or normal Strapi
return {
connector: "mongoose",
@viktorfa
viktorfa / serverless.yml
Last active Aug 17, 2020
Strapi Serverless config with S3 static bucket.
View serverless.yml
service: sls-strapi
provider:
name: aws
runtime: nodejs12.x
profile: <your-aws-profile>
logRetentionInDays: ${self:custom.vars.logRetentionInDays, 1}
environment:
ADMIN_JWT_SECRET: "Just using dummy"
@viktorfa
viktorfa / database.js
Created Aug 14, 2020
Database config in Strapi.
View database.js
// config/database.js
const getDatabaseConfig = ({ env }) => {
if (
env("IS_OFFLINE", null) === "true" ||
env("LAMBDA_RUNTIME_DIR", null) === null
) {
return {
connector: "bookshelf",
settings: {
@viktorfa
viktorfa / aurora.yml
Created Aug 14, 2020
Cloudformation template for creating an Aurora database in the Serverless framework.
View aurora.yml
# cloudformation/aurora.yml
Resources:
RDSCluster:
Type: AWS::RDS::DBCluster
Properties:
MasterUsername: DBUsername
MasterUserPassword: DBPassword
DatabaseName: DBName
Engine: aurora
@viktorfa
viktorfa / trim-node-modules.sh
Last active Sep 24, 2020
Script to remove heavy frontend stuff from Strapi node_modules.
View trim-node-modules.sh
# scripts/trim-node-modules.sh
#!/bin/bash
echo "trim-node-modules.sh"
du -hs node_modules/
node-prune # https://github.com/tj/node-prune
find $PWD/node_modules -maxdepth 1 -type d -name "*react*" -exec rm -rf {} +
@viktorfa
viktorfa / post-build.sh
Last active Aug 13, 2020
Post build script for Strapi Serverless
View post-build.sh
# scripts/post-build.sh
#!/bin/bash
echo "post-build.sh – moving assets of frontend build to dev/ folder."
mkdir $PWD/build/dev
find $PWD/build/ -type f -print0 | xargs -0 mv -t $PWD/build/dev
mv $PWD/build/dev/index.html $PWD/build
@viktorfa
viktorfa / server.js
Last active Aug 16, 2020
Server config for Strapi in Serverless
View server.js
// config/server.js
// This config is used both in `strapi build` and `strapi start`.
// So if we have a path prefix to the api, such as /dev or /v1,
// we need to use env variables to configure, as Strapi doesn't
// support path prefixes automagically.
module.exports = ({ env }) => {
let url = "<Insert Lambda endpoint url here after deploy.>";
@viktorfa
viktorfa / app.js
Last active Sep 24, 2020
Entry point for Serverless Strapi with serverless-http
View app.js
const startStrapi = require("strapi/lib/Strapi");
const serverless = require("serverless-http");
module.exports.handler = async (event, context) => {
if (!global.strapi) {
console.log("Cold starting Strapi");
await startStrapi({ dir: __dirname }).start();
}
const handler = serverless(global.strapi.app);
You can’t perform that action at this time.