|
1 | 1 | # Reaction Storefront Next.js Starter Kit |
2 | 2 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Freactioncommerce%2Freaction-next-starterkit?ref=badge_shield) |
3 | 3 |
|
4 | | - |
5 | 4 | _**Note:** This project is a work in progress and should not be used in production at this time._ |
6 | 5 |
|
7 | | -Reference Storefront application for [Reaction Commerce](https://reactioncommerce.com/). |
| 6 | +Reference headless ecommerce storefront for [Reaction Commerce](https://reactioncommerce.com/) v 2.0.0. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- Headless ecommerce starter kit built with [Next.js](https://nextjs.org/), [React](https://reactjs.org/), [MobX](https://mobx.js.org/getting-started.html), [GraphQL](https://graphql.org/), [Apollo Client](https://www.apollographql.com/docs/react/) |
| 11 | +- [Reaction GraphQL API](https://github.com/reactioncommerce/reaction/tree/master/imports/plugins/core/graphql) integration |
| 12 | +- Server-side rendering |
| 13 | +- Payments with [Stripe](https://stripe.com/) |
| 14 | +- Analytics with [Segment](https://segment.com/) |
| 15 | +- Reusable, customizable, themeable ecommerce React components from the new [Reaction Component Library](https://github.com/reactioncommerce/reaction-component-library/) with [Styled Components](https://www.styled-components.com/) |
| 16 | +- Fully-configured test suite: Jest snapshot testing, Mocha integration testing |
| 17 | +- Written in ES6, configured with ES6 |
| 18 | +- Containerized with Docker |
8 | 19 |
|
9 | 20 | ## Getting Started |
10 | | -_Follow steps as necessary. If you already have Reaction installed, you may be able to skip some of these steps._ |
11 | 21 |
|
12 | | -0. Prerequesites |
| 22 | +1. Requirements: |
| 23 | + |
13 | 24 | - Install [Docker](https://docs.docker.com/install/) and [Docker Compose](https://docs.docker.com/compose/install/). Docker Compose is included when installing Docker on Mac and Windows, but will need to be installed separately on Linux. |
| 25 | +- Install [Node.js](https://nodejs.org/en/) |
| 26 | +- Install [Reaction Platform](https://github.com/reactioncommerce/reaction-platform) |
| 27 | +- Make sure you are not running any applications on ports `3000` and `4000`. |
14 | 28 |
|
15 | | -1. Clone the main [Reaction repo](https://github.com/reactioncommerce/reaction) and checkout the `release-1.15.0` branch |
16 | | - ```sh |
17 | | - git clone [email protected]:reactioncommerce/reaction.git |
18 | | - cd reaction |
19 | | - git checkout release-1.15.0 |
| 29 | +1. Follow the instructions at [Reaction Platform](https://github.com/reactioncommerce/reaction-platform) to run Reaction, Reaction Hydra and the starterkit with Reaction Platform. |
20 | 30 |
|
21 | | - # change directory to the parent of your reaction install |
22 | | - cd .. |
23 | | - ``` |
| 31 | +After the initial bootstrapping, you can use `make start` to start all the necessary containers: |
24 | 32 |
|
25 | | -2. Clone this repo |
26 | | - ```sh |
27 | | - git clone [email protected]:reactioncommerce/reaction-next-starterkit.git |
28 | | - ``` |
| 33 | +```sh |
| 34 | +make start |
| 35 | +``` |
| 36 | + |
| 37 | +1. Once the `make` process finishes, the Reaction Platform services will be accessible at the following URLs: |
29 | 38 |
|
30 | | -3. Create a local docker network |
| 39 | +| Application | URL | |
| 40 | +| ------------ | ----------------------- | |
| 41 | +| `starterkit` | localhost:4000 | |
| 42 | +| GraphQL API | localhost:3000/graphiql | |
| 43 | +| `reaction` | localhost:3000 | |
31 | 44 |
|
32 | | - You'll need to create a docker network for the GraphQL service and the Reaction Storefront to communicate |
33 | | - ``` |
34 | | - docker network create api.reaction.localhost |
35 | | - ``` |
36 | | - You can run `docker network ls` to verify the network has been created. |
| 45 | +Visit the storefront at `localhost:4000` and the GraphQL API playground at `localhost:3000/graphiql`. |
37 | 46 |
|
38 | | -4. Start Reaction's GraphQL server |
39 | | - From your `reaction` directory run |
40 | | - ``` |
41 | | - docker-compose up -d --build |
42 | | - ``` |
43 | | - You'll need to run the full app at least once in order for step 5 to work. After this initial run, if you don't want to start the Reaction Meteor app, you can just run `docker-compose up -d devserver` |
| 47 | +1. To view the logs for the Starterkit, run: `docker-compose logs -f` |
44 | 48 |
|
45 | | -5. Generate a Meteor login token |
| 49 | +## Configuration |
46 | 50 |
|
47 | | - _This process will be eliminated once we've built out the GraphQL API for authentication_ |
48 | | - - Visit the Reaction Meteor shop [localhost:3000](http://localhost:3000) |
49 | | - - Open devtools and copy the Meteor.loginToken from `localStorage`. |
| 51 | +### Set up Stripe |
50 | 52 |
|
51 | | -6. Setup the Storefront environment |
| 53 | +When running the storefront and Reaction for the first time, you will need to configure Stripe payment processing and shipping options to test a complete order checkout flow. After signing up for a Stripe API key, follow these steps: |
52 | 54 |
|
53 | | - Navigate to the `reaction-next-starterkit` directory and create a `.env` file. |
54 | | - ```sh |
55 | | - cp .env.example .env |
56 | | - ``` |
57 | | -7. Start the storefront application in development mode using Docker Compose |
58 | | - ``` |
59 | | - docker-compose up -d --build |
60 | | - ``` |
| 55 | +1. Add public Stripe API key (`STRIPE_PUBLIC_API_KEY`) to `.env`. |
| 56 | +2. Open the Reaction Classic app, at `http://localhost:3000`. Log in as an Admin user. |
| 57 | +3. Open **Payments**: Enable Stripe by checking the box. Add a Stripe secret key and public key. |
| 58 | +4. Open **Shipping**: Enable flat-rate shipping by checking the box. Enable at least one type of flat-rate shipping by clicking on the option in the table and checking the box. |
61 | 59 |
|
62 | | -8. Visit the storefront on `localhost:4000` |
| 60 | +### Set up Analytics event tracking |
63 | 61 |
|
| 62 | +Read the docs for [setting up Segment or a custom analytics tracker](docs/tracking-events.md) |
| 63 | + |
| 64 | +## Documentation |
| 65 | +- [Starter Kit full documentation](./docs) |
| 66 | +- [Reaction Component Library repository](https://github.com/reactioncommerce/reaction-component-library), [documentation](https://github.com/reactioncommerce/reaction-component-library/tree/master/docs), and [component documentation](https://stoic-hodgkin-c0179e.netlify.com/) |
| 67 | +- [Reaction Docs: Using GraphQL](https://docs.reactioncommerce.com/docs/graphql-using) |
| 68 | +- [Reaction Docs: Testing with Jest](https://docs.reactioncommerce.com/docs/testing-reaction) |
| 69 | +- [Reaction Docs: Develping with Docker](https://docs.reactioncommerce.com/docs/installation-docker-development |
| 70 | +) |
64 | 71 |
|
65 | 72 | ## Development |
66 | 73 |
|
67 | | -### Build and run in development mode with logs |
| 74 | +The Reaction Platform runs the Starterkit with Docker, so you will have to use Docker commands to view logs, run commands inside the container and more. To run commands specifically for the Starterkit, make sure to change directories into the `reaction-next-starterkit` directory within the `reaction-platform` repository: |
| 75 | + |
| 76 | +```sh |
| 77 | +cd reaction-next-starterkit |
68 | 78 | ``` |
| 79 | + |
| 80 | +### Build and run in development mode with logs |
| 81 | +```sh |
69 | 82 | docker-compose up -d && docker-compose logs -f |
70 | 83 | ``` |
71 | 84 |
|
72 | 85 | ### Running Commands inside the container |
73 | | -``` |
| 86 | +```sh |
74 | 87 | docker-compose run --rm web [command] |
75 | 88 | ``` |
76 | 89 | Run any command inside a Docker container and then remove the container. Use this to run any tooling operations. Remember your project directory will be mounted and things will usually just work. |
@@ -140,56 +153,45 @@ Sometimes we need to test [`reaction-component-library`](https://github.com/reac |
140 | 153 |
|
141 | 154 | ## Cleanup Containers |
142 | 155 | Stop, and retain containers: |
143 | | -``` |
| 156 | +```sh |
144 | 157 | docker-compose stop |
145 | 158 | ``` |
146 | 159 |
|
147 | 160 | Stop, and remove containers: |
148 | | -``` |
| 161 | +```sh |
149 | 162 | docker-compose down |
150 | 163 | ``` |
151 | 164 |
|
152 | 165 | Stop, and remove containers, volumes and built images: |
153 | | -``` |
| 166 | +```sh |
154 | 167 | docker-compose down -v --rmi local |
155 | 168 | ``` |
156 | 169 |
|
157 | | -## Production |
158 | | -Running the command below will build the starterkit for production. |
| 170 | +## Building and running the production app locally |
159 | 171 |
|
160 | | -``` |
| 172 | +Sometimes it is helpful during development to make a production build of the app and run that locally. |
| 173 | + |
| 174 | +Run this command to build a Docker image with the production build of the app in it: |
| 175 | + |
| 176 | +```sh |
161 | 177 | docker build -t reaction-storefront --build-arg BUILD_ENV=production . |
162 | 178 | ``` |
163 | 179 |
|
164 | | -To start the app in production mode execute: |
| 180 | +Then, to start the app on your machine, make sure the Reaction API container is already running and enter: |
165 | 181 |
|
166 | | -``` |
| 182 | +```sh |
167 | 183 | docker run -d --name storefront -p ${port}:4000 --env-file .env --network api.reaction.localhost reaction-storefront |
168 | 184 | ``` |
169 | 185 |
|
170 | | -To stop the docker container after starting it with the above command |
171 | | -``` |
172 | | -docker stop storefront |
173 | | -``` |
174 | | -
|
175 | | -_**NOTE:** Replace the `${port}` with the localhost port you'd like the application to run at. I'm partial to 4040_ |
176 | | -_**NOTE:** The above command is assuming ether the `devserver` or `reaction` is also running._ |
177 | | -
|
178 | | -## Documentation |
179 | | -See our [full documentation](./docs) |
| 186 | +_**NOTE:** Replace the `${port}` with the localhost port you'd like the application to run at._ |
180 | 187 |
|
181 | | -## Features |
182 | | - - [Docker](https://docs.docker.com) |
183 | | - - [React](https://reactjs.org/) |
184 | | - - [Apollo](https://www.apollographql.com/docs/react/) |
185 | | - - [MobX](https://mobx.js.org/getting-started.html) |
186 | | - - [nextjs](https://github.com/zeit/next.js/) |
187 | | - - [Material UI](https://material-ui.com/) |
| 188 | +_**NOTE:** This is not the way to run the app in actual production deployment. This is only for running the production build locally for development, demo or trial purposes._ |
188 | 189 |
|
189 | | - ## Reference links for development |
190 | | - ### CSS in JS |
191 | | - - [Responsive Breakpoints](https://material-ui.com/layout/css-in-js/#responsive-breakpoints) |
| 190 | +To stop the Docker container after starting it with the above command, use: |
192 | 191 |
|
| 192 | +```sh |
| 193 | +docker stop storefront |
| 194 | +``` |
193 | 195 |
|
194 | 196 | ## License |
195 | 197 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Freactioncommerce%2Freaction-next-starterkit?ref=badge_large) |
0 commit comments