Skip to content

Instantly share code, notes, and snippets.

View viktorfa's full-sized avatar

Viktor Andersen viktorfa

  • Trondheim
View GitHub Profile
@viktorfa
viktorfa / CSRF_Pokedex_categories.html
Created April 19, 2018 13:01
Test the Pokedex categories page for CSRF attacks
<html>
<head>
</head>
<body>
<script>
const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'http://tdt4237.idi.ntnu.no:5017/categories/add',
'Origin': 'http://tdt4237.idi.ntnu.no:5017',
@viktorfa
viktorfa / s3cache.py
Created September 7, 2019 10:54
S3 HTTP Cache for Scrapy
# my_sls_scraper/extensions/s3cache.py
import boto3
import gzip
import json
import logging
import os
from botocore.exceptions import ClientError
from botocore.stub import Stubber
from time import time
@viktorfa
viktorfa / serverless.yml
Last active February 17, 2023 20:53
Serverless config for Strapi Serverless
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 / 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);
@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 / 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 / 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 / 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 / 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 / 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"