Skip to content
Snippets Groups Projects
Commit 5716c218 authored by meskio's avatar meskio :tent:
Browse files

Add deployment setup

parent 6d02b116
No related branches found
No related tags found
No related merge requests found
README 0 → 100644
# Cicer
Cicer is a web based software to manage the stock, purchases and balance of a consumer association. It has being created for the needs of the [Garbanzo Negro](http://garbanzonegro.org).
## deploy it
Build a copy using make:
```
$ make build
```
Create a secret for the authentication tokens:
```
$ head -c 21 < /dev/urandom | base64
```
Now you can copy the build folder and the cicer binary to your server and run it like:
```
$ ./cicer -assets 'path/to/build' -secret 'scret' -addr ':8000'
```
Instead of flags all the params can be passed as env variables see the names between `{` and `}` in:
```
$ ./cicer -h
```
## run for development
To run it in develop mode build and run the backend:
```
$ go build
$ ./cicer
```
And run the frontend with npm:
```
$ npm start
```
This will open a browser pointing to `http://localhost:3000` where you will see any changes you do in the javascript side (the backend side needs recompilation).
## Initialize data
When you run cicer it will print an authentication token that we can use to set up some initial data, see `setup.sh`:
```
$ ./setup.sh the.hexadecimal.token
```
...@@ -12,11 +12,13 @@ import ( ...@@ -12,11 +12,13 @@ import (
func main() { func main() {
var ( var (
dbPath = flag.String("db-path", env.String("./test.db", "DB_PATH"), "Path where the sqlite will be located") dbPath = flag.String("db-path", env.String("./test.db", "DB_PATH"), "Path where the sqlite will be located {DB_PATH}")
addr = flag.String("addr", env.String(":8080", "HTTP_ADDR", "ADDR"), "Address where the http server will bind") addr = flag.String("addr", env.String(":8080", "HTTP_ADDR", "ADDR"), "Address where the http server will bind {HTTP_ADDR}")
signKey = flag.String("signkey", env.String("", "SIGNKEY"), "Sign key for authentication tokens. DO NOT LEAVE UNSET!!!") signKey = flag.String("signkey", env.String("", "SIGNKEY"), "Sign key for authentication tokens. DO NOT LEAVE UNSET!!! {SIGNKEY}")
assets = flag.String("assets", env.String("./build", "ASSETS_PATH"), "Path to the assets (js, html, ...) {ASSETS_PATH}")
) )
flag.Parse() flag.Parse()
log.Println("listening in address:", *addr)
r := mux.NewRouter() r := mux.NewRouter()
apiRouter := r.PathPrefix("/api/").Subrouter() apiRouter := r.PathPrefix("/api/").Subrouter()
...@@ -25,5 +27,7 @@ func main() { ...@@ -25,5 +27,7 @@ func main() {
log.Panicln("Can't open the database:", err) log.Panicln("Can't open the database:", err)
} }
log.Println("assets:", *assets)
r.PathPrefix("/").Handler(http.FileServer(http.Dir(*assets)))
log.Fatal(http.ListenAndServe(*addr, r)) log.Fatal(http.ListenAndServe(*addr, r))
} }
#!/bin/sh
TOKEN="$1"
curl -H "x-authentication: $TOKEN" -X "POST" -d '{"num": 10, "name": "foo", "email": "foo@example.com", "password": "foo", "balance": 10000}' localhost:8080/api/member
curl -H "x-authentication: $TOKEN" -X "POST" -d '{"code": 234, "name": "aceite", "price": 1700, "stock": 35}' localhost:8080/api/product
curl -H "x-authentication: $TOKEN" -X "POST" -d '{"code": 120, "name": "alubias", "price": 200, "stock": 20}' localhost:8080/api/product
curl -H "x-authentication: $TOKEN" -X "POST" -d '{"code": 302, "name": "esparragos", "price": 300, "stock": 15}' localhost:8080/api/product
...@@ -52,7 +52,7 @@ class App extends React.Component { ...@@ -52,7 +52,7 @@ class App extends React.Component {
componentDidMount() { componentDidMount() {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
if (token !== "") { if (token) {
const num = localStorage.getItem("num"); const num = localStorage.getItem("num");
const role = localStorage.getItem("role"); const role = localStorage.getItem("role");
this.setState({ isLoged: true, num, role, token }); this.setState({ isLoged: true, num, role, token });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment