From ad6cc13681006b09db0b13692abafb4bf73d4712 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Tue, 26 Jun 2018 15:34:38 +0200 Subject: [PATCH] Add some doc --- LICENSE.md | 21 ++++++++++++ README.md | 82 ++++++++++++++++++++++++++++++++++++++-------- config/prod.env.js | 1 + server/__main__.py | 6 +++- src/api/index.js | 2 +- 5 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1354996 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Phyks (Lucas Verney) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 7938ad9..87cfaaf 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,82 @@ -# cyclassist +Cyclassist +========== -> A Vue.js project +> Track and share issues (work, interruption in routes, parked cars) in +> realtime on bike lanes! -## Build Setup +This app is made of two parts: a client webapp and a server part to store and +serve the issues. + +## Client part + +### Build setup ``` bash -# install dependencies -npm install +# Install JS dependencies +yarn install -# serve with hot reload at localhost:8080 -npm run dev +# Serve with hot reload at localhost:8080 +yarn dev -# build for production with minification -npm run build +# Build for production with minification +yarn build -# build for production and view the bundle analyzer report -npm run build --report +# Build for production and view the bundle analyzer report +yarn build --report ``` -For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). +### Useful environment variables + +You can pass a few environment variables to the `yarn build|dev` commands to +adapt the behavior to your needs. + +* `PUBLIC_PATH=https://.../foobar` to serve the app from a subdirectory. +* `API_BASE_URL=https://...` to specify the location of the server (defaults + to `/`). The value should end with a trailing slash. -## Serving from a subdirectory +## Server part + +### Build setup + +``` bash +# Install Python dependencies +pip install -r requirements.txt + +# Start the server +python -m server +``` + +It is better to use a dedicated `virtualenv` if you can :) + +### Useful environment variables + +You can pass a few environment variables to the `python -m server` command to +adapt its behavior: + +* `HOST=` to specify the host to listen to (defaults to `127.0.0.1` which + means `localhost` only). +* `PORT=` to specify the port to listen on (defaults to `8081`). + + +## Contributing + +The quickest way to get started is to simply run ``` -PUBLIC_PATH=https://.../foobar yarn build +API_BASE_URL=http://127.0.0.1:8081/ yarn dev ``` + +to spawn the client-side webapp, listening on `localhost:8080` and + +``` +python -m server +``` + +to spawn the server-side part, listening on `localhost:8081`. + + +## License + +This software is licensed under an MIT license, unless explicitly mentionned +otherwise. diff --git a/config/prod.env.js b/config/prod.env.js index 1aa0fbc..493ebe2 100644 --- a/config/prod.env.js +++ b/config/prod.env.js @@ -1,4 +1,5 @@ 'use strict' module.exports = { NODE_ENV: '"production"', + API_BASE_URL: JSON.stringify(process.env.API_BASE_URL), } diff --git a/server/__main__.py b/server/__main__.py index a840e0c..5bba1c9 100644 --- a/server/__main__.py +++ b/server/__main__.py @@ -2,6 +2,7 @@ # coding: utf-8 import functools import json +import os import bottle @@ -21,4 +22,7 @@ if __name__ == "__main__": json_dumps=functools.partial(json.dumps, cls=DateAwareJSONEncoder) ) ) - bottle.run(host='0.0.0.0', port='8081') + bottle.run( + host=os.environ.get('HOST', '127.0.0.1'), + port=int(os.environ.get('PORT', '8081')) + ) diff --git a/src/api/index.js b/src/api/index.js index 3597cf4..d55ea2f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -2,7 +2,7 @@ require('es6-promise').polyfill(); require('isomorphic-fetch'); // With trailing slash -export const BASE_URL = process.env.API_BASE_URL || 'http://127.0.0.1:8081/'; // TODO +export const BASE_URL = process.env.API_BASE_URL || '/'; export function saveReport(type, lat, lng) { return fetch(`${BASE_URL}api/v1/reports`, {