Skip to content

Commit

Permalink
CORS error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
IakMastro committed May 24, 2021
1 parent 9d5bfc9 commit 642d69e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
26 changes: 10 additions & 16 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
app.config.from_object(__name__)

# Mongodb connection initialization to database gameStore'
app.config['MONGO_URI'] = "mongodb://datinguser:datinguserpasswd@mongodb:27017/tinderClone?authSource=admin"
app.config['MONGO_URI'] = "mongodb://datinguser:datinguserpasswd@mongodb_tinder:27017/tinderClone?authSource=admin"
mongo = PyMongo(app)

# Enable CORS (CORS is a library that enables cross-origin requests)
Expand Down Expand Up @@ -56,15 +56,16 @@ def register():
response_object = {'status': 'success'}
post_data = request.get_json()

if mongo.db.users.find_one({'email': post_data['email']}) is None:
email = post_data.get('email')
if mongo.db.users.find_one({'email': email}) is None:
mongo.db.users.insert({
'_id': uuid.uuid4().hex,
'email': post_data['email'],
'username': post_data['username'],
'name': post_data['name'],
'surname': post_data['surname'],
'password': post_data['password'],
'birthday': post_data['birthday'],
'email': email,
'username': post_data.get('username'),
'name': post_data.get('name'),
'surname': post_data.get('surname'),
'password': post_data.get('password'),
'birthday': post_data.get('birthday'),
'type': 'free'
})

Expand All @@ -73,14 +74,7 @@ def register():
else:
response_object['message'] = 'Email already exists'

return jsonify(response_object)


@app.after_request
def add_headers(response):
response.headers.add('Access-Control-Allow-Origins', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
return response
return jsonify(response_object, success=True)


if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
},
message: '',
showMessage: false,
path: 'http://tinder_api:5000',
path: 'http://localhost:5000',
};
},
Expand All @@ -132,9 +132,10 @@ export default {
methods: {
onLogin() {
const payload = {
username: $('#inputUsername').val(),
password: $('#inputPassword').val(),
email: $('#email').val(),
password: $('#pwd').val(),
};
console.log(payload)
this.login(payload);
},
Expand Down Expand Up @@ -184,6 +185,8 @@ export default {
birthday: this.registerForm.birthday
};
console.log(payload)
this.signup(payload);
} else {
this.message = 'Passwords must match';
Expand Down
6 changes: 3 additions & 3 deletions db/init-db.d/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ db.users.drop();
db.users.insertMany([
{
_id: 1,
email: 'foo.bar@email.com',
name: "foo.bar",
password: 'lol password ez',
email: '[email protected]',
name: "foo",
password: 'bar',
birthday: "1970/01/01",
gender: "Male",
weight: '80kg',
Expand Down
17 changes: 13 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ services:
environment:
NODE_APP: client
NODE_ENV: development
links:
depends_on:
- backend
networks:
- tinder_net

backend:
build: backend
Expand All @@ -25,12 +27,13 @@ services:
FLASK_APP: app
FLASK_RUN_HOST: 0.0.0.0
FLASK_ENV: development
links:
depends_on:
- mongo
networks:
- tinder_net

mongo-express:
image: mongo-express
restart: always
container_name: mongo-express_tinder
ports:
- "8081:8081"
Expand All @@ -39,11 +42,12 @@ services:
ME_CONFIG_MONGODB_ADMINPASSWORD: datinguserpasswd
links:
- mongo
networks:
- tinder_net

mongo:
build: db
container_name: mongodb_tinder
restart: always
ports:
- "27017:27017"
volumes:
Expand All @@ -52,3 +56,8 @@ services:
MONGO_INITDB_ROOT_USERNAME: datinguser
MONGO_INITDB_ROOT_PASSWORD: datinguserpasswd
MONGO_INITDB_DATABASE: tinderClone
networks:
- tinder_net

networks:
tinder_net:
2 changes: 1 addition & 1 deletion restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

docker-compose down
sudo rm -rf db/data
docker-compose up -d --force-recreate
docker-compose up -d --force-recreate --build

0 comments on commit 642d69e

Please sign in to comment.