Coder Social home page Coder Social logo

Comments (11)

abhisuri97 avatar abhisuri97 commented on July 28, 2024

The SERVER_NAME variable is set based on your server settings from what I can understand. I am not sure exactly what this means for Amazon EC2. But open a PR with your solution and I'll take a look at it and see whats the best way to integrate it. Just as a general question, are you running your application with the FLASK_CONFIG env var set to production?

from flask-base.

Mattpwinchester avatar Mattpwinchester commented on July 28, 2024

I have the environment variable set to development.

Isn't the SERVER_NAME supposed to be set in the env file? The server setup I'm running is a nginx server pointing upstream to this (flask-base) server instance which I run using the Foreman config:

redis: redis-server
web: python -u manage.py runserver --host 127.0.0.1 --port 8000
worker: python -u manage.py run_worker

I tried it with the host defined like that and without it with the same results.

from flask-base.

abhisuri97 avatar abhisuri97 commented on July 28, 2024

just wondering. if you set the environment variable FLASK_CONFIG=production does that change anything? sorry for being late getting to this, had a few midterms this week.

from flask-base.

Mattpwinchester avatar Mattpwinchester commented on July 28, 2024

Sorry about taking so long to respond.

I tried setting the FLASK_CONFIG=production flag in the .env file with the other flask parameters and it doesn't appear to be changing anything other than now the server gives me a RaygunProvider error: ApiKey not set, errors will not be transmitted.

Shut down the server and restarted it with the same issue. The only method I have to work around this issue is to set the external flag in url_for() to false and then have a string for my server name that I append with the internal URL. This is sloppy and I would like to have flask-base give me the name of the website if possible. Even if I have to pre-load it into the env.py file or elsewhere.

from flask-base.

abhisuri97 avatar abhisuri97 commented on July 28, 2024

Hey Matt,
no problem on taking a while to respond. So I have tried to replicate this issue on my personal docker instance running on Digital ocean and it consistently puts my server domain in emails. If I manage to replicate the issue (or if someone else mentions it), I will merge the fix into the code base...but until then, a more maintainable fix would be to go to your config.env (or .env if you are using an older version of flask-base) file and add the line

SERVER_NAME=http://yourdomainnamehere.blah

Inside of config.py after line 58 add
SERVER_NAME = os.environ.get('SERVER_NAME') or 'http://localhost:5000'

and make sure that you change _external mentions to True instead of False

from flask-base.

Mattpwinchester avatar Mattpwinchester commented on July 28, 2024

I followed your instructions and I am unable to view any of the website pages after restarting the server.

My configuration is as follows:

  1. Using foreman to load the website,rq,redis:
    redis: redis-server
    web: python -u manage.py runserver --port 8001
    worker: python -u manage.py run_worker

  2. Instance is run on an EC2 amazon instance (ubuntu 14.04)

  3. Running in app.config development mode

  4. Nginx is handling SSL with letsencrypt and passing data upstream to the app running on port 8001.

If you need clarification or additional information I will see what I can provide.

from flask-base.

abhisuri97 avatar abhisuri97 commented on July 28, 2024

sorry change the line to

SERVER_NAME = os.environ.get('SERVER_NAME') or 'localhost:5000'

OR for a slightly more managable configuration

on line 59:

SERVER_NAME = 'localhost:5000'

somewhere under ProductionConfig add

SERVER_NAME = os.environ.get('SERVER_NAME')

this fix will run on localhost 5000 in development mode and run on the actual server name when you set FLASK_CONFIG to production

i think that should work. I don't recall whether SERVER_NAME will need http:// in front of it...most likely not now that i think about it.

from flask-base.

Mattpwinchester avatar Mattpwinchester commented on July 28, 2024

I tried your suggestions and it didn't work. Do I have to run the website on port 5000 in order for this to work? If so how do I change that to port 8001?

The website runs but I also get 404s for all of the webassets_external; How do I fix that?

from flask-base.

abhisuri97 avatar abhisuri97 commented on July 28, 2024

So on docker, you need to bind your local port (flask sets this to 5000) to whatever your external port will be.

from flask-base.

Mattpwinchester avatar Mattpwinchester commented on July 28, 2024

I'm not working with docker, the server is hosted on AWS. I have no idea how docker got added to this conversation.

After trying your suggestions I still can't get the server to issue confirmation links with the server name I give it or even the port number.

from flask-base.

abhisuri97 avatar abhisuri97 commented on July 28, 2024

sorry about the docker thing, was working on a docker project while i wrote that.

but since I haven't been able to replicate the issue on my end, the only thing i can think of is to have a separate environment variable just for your emailing URL (dont use SERVER_NAME since that is reserved by Flask for handling url routing etc) or just hardcoding it in as you said in your original message. I don't have a ton of experience launching things on AWS so I am not the best person to reach out to about this.

Also about your question regarding whether it has to be on port 5000, you can change that by explicitly adding the runserver command in manager.py as shown here http://stackoverflow.com/questions/34824988/run-app-from-flask-migrate-manager

from flask-base.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.