Skip to content

rtunazzz/atc-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ATC Server made with Go

Running

With docker

Make sure you have docker installed.

You can either pull the image from dockerhub:

docker run -p 9000:9000 --name atc-server arturhnat/atc-server:latest

or after cloning this repo, you can:

  1. Build the image
docker build -t atc-server .
  1. Run the image
docker run -p 9000:9000 atc-server
  1. Your server will now be available at http://localhost:9000/

With Go

Make sure you have go installed.

  1. Download modules
go mod download
  1. Install modules
go install .
  1. Run the server
go run main.go

Usage

The server has 4 main routes:


Adding more sites

All supported sites are configured in the config.json file and are loaded dynamically, so to add a new site for either ATC/ Wishlist, all you need to do is add the proper URLs to the config file.

If you'd want to add another site to the locale picker, all you need to do is add an entry into the router file. You may also want to configure the setLocaleHandler function.

Each site in the config file is expected to have the following structure:

"name_of_the_site": { // this will then be the required query parameter for the /atc and /wishlist routes
    "run_script": true, // whether or not the default form handler should be overwritten with a different script, specified by the script_name below
    "script_name": "site.js", // name of the script to execute
    "atc_supported": true, // whether or not Adding to Cart is supported
    "wishlist_supported": true, // whether or not Adding to Wishlist is supported
    "wait_for_submit": false, // Whether or not should the script wait for the form to finish submitting before redirecting
    "locales": { // each entry in the locales object is understood as a new locale. There always has to be at least one, default one named 'default'.
      "default": {
        "atc_url": "https://site.com/add-to-cart", // URL to which the ATC form gets POSTed
        "atc_redirect_url": "https://site.com/checkout", // URL to which the user will be redirected after ATC, can be anything
        "wishlist_url": "https://site.com/add-to-wishlist", // URL to which the Wishlist form gets POSTed
        "wishlist_redirect_url": "https://site.com/wishlist", // URL to which the user will be redirected after ATC, can be anything
      }
    }
  }