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 / 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 / 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 / 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/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",
// config/plugins.js
module.exports = ({ env }) => ({
upload: {
provider: "aws-s3",
providerOptions: {
params: {
Bucket: env("BUCKET_NAME"),
},
},
@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