Code Monkey home page Code Monkey logo

webproducer's Introduction

WebProducer

Board Status

WebProducer, or simply WP, is a serverless application for publishing content to the web. It equally supports websites and web applications with a lean, streams based, architecture.

The current version is dependent upon the Amazon AWS stack, including IAM, Lambda, S3+CloudFront. Support for other providers including Google and Microsoft is planned for the future.

The core of the module is a NodeJS Lambda function. This function is intended to act as the endpoint for a webhook from your preferred CMS. Changing content in the CMS should trigger the webhook which will then

  1. Fetch the full content from the CMS
  2. Fetch the list of existing files and their ETags
  3. Load and register the theme
  4. Merge the content with the theme to produce raw output
  5. Process the raw output to minify all HTML, CSS and JavaScript files
  6. Create a sitemap.xml file
  7. Create any optional RSS files if syndicated content is detected
  8. Compare built files to list fetched in step 2 and build a difference
  9. Stream the difference to the target
  10. If the target is an S3 bucket and a CloudFront id has been specified then CloudFront will be invalidated

Prerequisites

The versions listed for these prerequisites are current at the time of writing. More recent versions will likely work but "your mileage may vary".

  • A good code editor.
  • Node.js v12.13.0† and NPM 6.14.5
  • Git 2.25

† WebProducer is often used in AWS Lambda FaaS. The current hightest Node runtime version supported by AWS is v12.

Setup and Configuration

Clone this repository as your new project git clone [email protected]:tforster/webproducer.git ~/dev/

Usage

  1. Install using your preferred package manager. E.g. npm i -S git+ssh://[email protected]/tforster/webproducer.git#semver:v0.7.1

  2. Create webproducer.yml. The following example shows multiple formats for data, templates and destination by way of aliases introduced in 0.6.0.

    data: ${env:DATA_ALIAS} # Uses an environment variable to specify an alias
    templates: template-fs # Points to an alias
    destination: # References the destination object directly
      type: filesystem
      base: ./dist
      archive: false # default
    
    ####################
    # Template Aliases #
    ####################
    
    template-fs:
      type: filesystem
      base: ./src
    
    template-s3:
      type: s3
      base: s3://wp.somedomain.com/${env:STAGE}
      region: ca-central-1
    
    #######################
    # Destination Aliases #
    #######################
    
    destination-fs:
      type: filesystem
      base: ./dist
      archive: false # default
    
    destination-s3:
      type: s3
      base: s3://www.somedomain.com
      region: ca-central-1
      archive: false # default
    
    ################
    # Data Aliases #
    ################
    
    data-gql:
      type: graphql
      base: https://graphql.datocms.com/
      token: ${env:GRAPHQL_API_TOKEN}
      published: ${env:PUBLISHED}
    
    data-get-request: # REST not implemented. Future consideration only.
      type: get
      base: https://some-endpoint.com/this/that
    
    data-sql: # SQL not implemented. Future consideration only.
      type: sql
      base: Server=myServerName\myInstanceName;Database=myDataBase;User Id=${env:DB_USERNAME};Password=${env:DB_PASSWORD};
    
    data-mongodb: # Mongo not implemented. Future consideration only.
      type: mongo
      base: mongodb://mongodb0.example.com:27017
  3. Create .env file using the following schema. Note that most of the parameters are not secrets and could easily be stored in webproducer.yml, however, we have found that externalising to the .env file makes it easier to toggle between template and destination locations during development of a consuming app.

    ALIAS_DATA=data-gql               # Alias the data source
    ALIAS_TEMPLATES=template-s3       # Alias the template source
    ALIAS_DESTINATION=destination-s3  # Alias the destination source
    GRAPHQL_API_TOKEN=***             # Only needed if you are using GraphQL and on a private endpoint
    STAGE=stage                       # One of dev, stage or prod
    PUBLISHED=true                    # Typically only required for GraphQL to distinguish between draft and published content
    CLOUDFRONT_ID=                    # The production CloudFront distribution to invalidate on deploy. Leave blank for dev and stage

Change Log

See CHANGELOG.md

Meta

Troy Forster – @tforster – [email protected]

See LICENSE for more information.

https://github.com/tforster/webproducer

Contributing

See CONTRIBUTING.md

webproducer's People

Contributors

dependabot[bot] avatar tforster avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

webproducer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.