GithubHelp home page GithubHelp logo

211211 / subdomains-cookies Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emilycoco/subdomains-cookies

0.0 1.0 0.0 3 KB

Simple Example of sharing cookies across subdomains and mimicking subdomains locally

JavaScript 62.72% HTML 37.28%

subdomains-cookies's Introduction

Simple Example of sharing cookies across subdomains and mimicking subdomains locally

This project has one simple api, with two routes, each of which is used for display data by one static page. The static pages share cookies by setting them on a shared root domain, ".mydomain.com". This is a useful way to share authentication or other user data across subdomains.

To Run (each in a new tab):

node api/server.js
node staticSubdomainOne/server.js
node staticSubdomainTwo/server.js

Edit your /etc/hosts file to alias localhost to mydomain.com, see the file sample_host_file for an example.

This allows you to mimic subdomains locally, because each distinct port counts as a subdomain of the root domain mydomain.com. Simply setting multiple ports on localhost won't work because a root domain needs to have at least two parts. It also won't work to mimic more than one layer of subdomains, like http://web.mydomain.com:8000 because you can't set an alias by port in your hosts file.

See the pages in action by opening up http://mydomain.com:8001 and http://mydomain.com:8002. Setting or changing a cookie value on either one will be shared between the two. This cookie will also be sent with each api request as a header, because it's on the same root domain. In production, it may be a good idea to set cookies for web use on a separate path so they don't impact the size of api calls.

subdomains-cookies's People

Contributors

emilycoco avatar

Watchers

James Cloos avatar

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.