Skip to content

Instantly share code, notes, and snippets.

View viktorfa's full-sized avatar

Viktor Andersen viktorfa

  • Trondheim
View GitHub Profile
@viktorfa
viktorfa / database.js
Last active August 17, 2020 09:39
Database config for Strapi in Lambda with SQLite
// 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",
// config/plugins.js
module.exports = ({ env }) => ({
upload: {
provider: "aws-s3",
providerOptions: {
params: {
Bucket: env("BUCKET_NAME"),
},
},
// 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 April 28, 2022 08:00
Strapi Serverless config with S3 static bucket.
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 August 14, 2020 14:32
Database config in Strapi.
// 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 August 14, 2020 14:20
Cloudformation template for creating an Aurora database in the Serverless framework.
# 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 September 24, 2020 19:29
Script to remove heavy frontend stuff from Strapi node_modules.
# 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 March 14, 2021 13:48
Post build script for Strapi Serverless
# 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 August 16, 2020 21:06
Server config for Strapi in Serverless
// 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 August 29, 2021 19:32
Entry point for Serverless Strapi with serverless-http
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);