diff --git a/bin/build.sh b/bin/build.sh index ec35f9d8..0a5c59db 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -5,9 +5,13 @@ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) MNML_PATH=$(realpath "$DIR/../") if [ ! -f $MNML_PATH/etc/mnml.env ]; then - echo "create an env file in $MNML_PATH/etc/mnml.env" - echo "see $MNML_PATH/etc/mnml.SAMPLE.env for details" - exit 1; + echo "-----------------------------------------------" + echo "creating an env file in $MNML_PATH/etc/mnml.env" + echo "-----------------------------------------------" + + echo "export MNML_USER=\"$(whoami)\"" >> $MNML_PATH/etc/mnml.env + echo "export MNML_PG_PASSWORD=\"$(openssl rand -base64 16)\"" >> $MNML_PATH/etc/mnml.env + echo "export MNML_PG_HOST=\"localhost\"" >> $MNML_PATH/etc/mnml.env fi source $MNML_PATH/etc/mnml.env @@ -40,18 +44,22 @@ sudo -u postgres psql -c "alter user mnml with encrypted password '$MNML_PG_PASS cd $MNML_PATH/ops && npm run migrate # RUST SETUP +echo "DATABASE_URL=postgres://mnml:$MNML_PG_PASSWORD@$MNML_PG_HOST/mnml" > $MNML_PATH/server/.env # cargo build # cp -r $MNML_PATH/server/target/release /opt/mnml/bin # NGINX if [ ! -f $MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf ]; then - echo "create an env file in $MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf" - echo "see $MNML_PATH/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf for details" - exit 1; + echo "-----------------------------------------------" + echo "using development nginx config" + echo "$MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf" + echo "-----------------------------------------------" + + cp $MNML_PATH/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf $MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf fi sudo cp $MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf /etc/nginx/sites-available sudo ln -nfs /etc/nginx/sites-available/mnml.gg.nginx.conf /etc/nginx/sites-enabled/mnml.gg.nginx.conf -cd $MNML_PATH/client && npm run build +# cd $MNML_PATH/client && npm run build sudo service nginx restart diff --git a/client/package.json b/client/package.json index e8635a23..4f9327d6 100644 --- a/client/package.json +++ b/client/package.json @@ -4,9 +4,9 @@ "description": "", "main": "index.js", "scripts": { - "start": "parcel watch index.html --out-dir /var/lib/mnml/public", + "start": "parcel watch index.html --out-dir /var/lib/mnml/public/dist", "anims": "parcel animations.html --host 0.0.0.0 --port 40080 --no-source-maps", - "build": "parcel build index.html --out-dir /var/lib/mnml/public", + "build": "parcel build index.html --out-dir /var/lib/mnml/public/dist", "scss": "node-sass --watch assets/scss -o assets/styles", "lint": "eslint --fix --ext .jsx src/", "test": "echo \"Error: no test specified\" && exit 1" diff --git a/client/src/animations.socket.jsx b/client/src/animations.socket.jsx index 424114b1..c1756396 100644 --- a/client/src/animations.socket.jsx +++ b/client/src/animations.socket.jsx @@ -7,7 +7,7 @@ const actions = require('./actions'); const { TIMES } = require('./constants'); const { getCombatSequence } = require('./utils'); -const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://mnml.gg/api/ws' : 'ws://localhost:40000/api/ws'; +const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://mnml.gg/api/ws' : 'ws://localhost/api/ws'; function createSocket(store) { let ws = null; diff --git a/client/src/socket.jsx b/client/src/socket.jsx index ca1e1703..8d9c71f0 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -1,7 +1,7 @@ const toast = require('izitoast'); const cbor = require('borc'); -const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://mnml.gg/api/ws' : 'ws://localhost:40000/api/ws'; +const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://mnml.gg/api/ws' : 'ws://localhost/api/ws'; function errorToast(err) { console.error(err); diff --git a/client/src/utils.jsx b/client/src/utils.jsx index da74c26d..3dcf01b5 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -352,11 +352,9 @@ const removeTier = skill => { return skill; }; - -const SERVER = process.env.NODE_ENV === 'production' ? '/api/' : 'http://localhost:40000/api'; function postData(url = '/', data = {}) { // Default options are marked with * - return fetch(`${SERVER}${url}`, { + return fetch(`/api${url}`, { method: 'POST', // *GET, POST, PUT, DELETE, etc. // mode: 'no-cors', // no-cors, cors, *same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached @@ -379,7 +377,6 @@ module.exports = { getCombatSequence, getCombatText, postData, - SERVER, NULL_UUID, STATS, COLOURS, diff --git a/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf b/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf index a70c95d1..12d0d813 100644 --- a/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf +++ b/etc/nginx/sites-available/mnml.gg.DEV.nginx.conf @@ -1,3 +1,5 @@ +error_log /var/log/nginx/mnml.nginx.log debug; + upstream mnml { server 127.0.0.1:40000; } @@ -9,10 +11,9 @@ map $http_upgrade $connection_upgrade { # DEV server { - root /var/lib/mnml/public/; - index index.html; - location / { + root /var/lib/mnml/public/dist; + index index.html; try_files $uri $uri/ =404; } diff --git a/ops/migrations/20190709132153_mtx.js b/ops/migrations/20190709132153_mtx.js new file mode 100644 index 00000000..61488615 --- /dev/null +++ b/ops/migrations/20190709132153_mtx.js @@ -0,0 +1,23 @@ +exports.up = async knex => { + await knex.schema.createTable('mtx', table => { + table.uuid('id') + .primary(); + + table.uuid('account') + .notNullable() + .index(); + + table.foreign('account') + .references('id') + .inTable('accounts') + .onDelete('RESTRICT'); + + table.string('variant') + .notNullable() + .index(); + + table.timestamps(true, true); + }); +}; + +exports.down = async () => {}; \ No newline at end of file diff --git a/server/src/account.rs b/server/src/account.rs index b21dd440..8e1d4c9f 100644 --- a/server/src/account.rs +++ b/server/src/account.rs @@ -231,7 +231,8 @@ pub fn account_create(name: &String, password: &String, code: &String, tx: &mut None => return Err(err_msg("account not created")), }; - for _i in 0..3 { + // 3 constructs for a team and 1 to swap + for _i in 0..4 { construct_spawn(tx, ConstructSpawnParams { name: generate_name() }, id)?; }