Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin mhaagens

  • AmmaCreative
  • Oslo, Norway
View GitHub Profile
@mhaagens
mhaagens / docker-compose.yml
Created Jul 1, 2019
Elasticsearch + App Search
View docker-compose.yml
version: "3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
environment:
- cluster.name=elasticsearch-oss
- discovery.type=single-node
- cluster.routing.allocation.disk.threshold_enabled=false
- bootstrap.memory_lock=true
- http.cors.enabled=true
@mhaagens
mhaagens / Dockerfile
Created Oct 25, 2018
Docker Wordpress Development
View Dockerfile
FROM nginx:latest
RUN echo "upstream php { server wordpress:9000; }" > /etc/nginx/conf.d/upstream.conf
COPY default.conf /etc/nginx/conf.d/default.conf
View authentication_middleware.js
import jwt from "jsonwebtoken";
import User from "@server/models/user_model";
const PRODUCTION = process.env.NODE_ENV === "production";
export default (options) => async (req, res, next) => {
const refreshToken = req.cookies["refresh_token"];
const accessToken = req.cookies["access_token"];
const csrfHeader = req.get("X-Csrf-Token");
@mhaagens
mhaagens / app.js
Created Jul 1, 2018
Authentication and authorization using GraphQL Schema Directives: src/app.js snippet
View app.js
const server = new ApolloServer({
typeDefs,
resolvers,
schemaDirectives: {
requireAuth: requireAuthDirective
}
});
@mhaagens
mhaagens / requireAuthDirective.js
Last active Feb 15, 2019
Authentication and authorization using GraphQL Schema Directives: src/directives/requireAuthDirective.js
View requireAuthDirective.js
const {
SchemaDirectiveVisitor,
AuthenticationError
} = require("apollo-server");
class RequireAuthDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field) {
const { resolve = defaultFieldResolver } = field;
const { role } = this.args;
field.resolve = async function(...args) {
@mhaagens
mhaagens / post.js
Last active Jul 2, 2018
Authentication and authorization using GraphQL Schema Directives: src/models/post.js
View post.js
const { gql } = require("apollo-server");
const mockPosts = [
{ id: 1, title: "Helvetica and Times New Roman walk into a bar. Get out of here! shouts the bartender. We don't serve your type!", ownerId: 1 },
{ id: 2, title: "Why do we tell actors to break a leg? Because every play has a cast.", ownerId: 2 },
{ id: 3, title: "Did you hear about the mathematician who’s afraid of negative numbers? He'll stop at nothing to avoid them.", ownerId: 1 }
];
module.exports.postDefs = gql`
extend type Query {
@mhaagens
mhaagens / schema.js
Last active Jul 2, 2018
Authentication and authorization using GraphQL Schema Directives: schema.js
View schema.js
const { gql } = require("apollo-server");
const _ = require("lodash");
const { postDefs, postResolvers } = require("./models/post.js");
module.exports.typeDefs = gql`
enum Role {
ADMIN
USER
}
@mhaagens
mhaagens / dev_server.js
Created Jul 1, 2018
Authentication and authorization using GraphQL Schema Directives: dev_server.js
View dev_server.js
const path = require("path");
const chokidar = require("chokidar");
const reload = require("require-reload")(require);
let server = reload("./src/app.js");
const srcDir = path.resolve(__dirname, "src");
const watcher = chokidar.watch(srcDir + "/**/*.js", {});
watcher.on("ready", () =>
server
@mhaagens
mhaagens / app.js
Last active Jul 2, 2018
Authentication and authorization using GraphQL Schema Directives: src/app.js
View app.js
const { ApolloServer } = require("apollo-server");
const { typeDefs, resolvers } = require("./schema.js");
const requireAuthDirective = require("./directives/requireAuthDirective");
const server = new ApolloServer({
typeDefs,
resolvers,
schemaDirectives: {
requireAuth: requireAuthDirective
},
@mhaagens
mhaagens / Dockerfile
Created Oct 13, 2017
Node Frontend Docker Quickstart
View Dockerfile
FROM node:alpine
WORKDIR /code
run apk --no-cache add --virtual native-deps \
g++ gcc libgcc libstdc++ linux-headers make python && \
npm install --quiet node-gyp -g && \
npm rebuild node-sass --force && \
apk del native-deps
CMD ["yarn", "start"]
EXPOSE 9000