Why do I get a 404 for my static webpage? - amazon-web-services

I’ve been working for about 2 years developing full stack apps (which were fairly mature when I get to them initially) and am starting up my first from scratch. I spent the day spinning up an EC2 instance, loading the dependencies for my stack (Postgres, golang, react), and all the other frills a shiny new machine needs (tmux, npm, vim plugins, git integration etc). I’m now stuck.
I used create-react-app to get started on my front end and running npm start to have a build going. To see this, I can go to my instanceip:3000.
I created golang server code which is serving up on port 8080 and I can hit my helloworld code by going to instanceip:8080/hello.
I added an axios call in my react code to get endpoint /hello which returns a 404.
I also attempted to make my golang handle the index.js as a static page for the instanceip:8080 and that returns a 404.
How do I get my different ports to play nice? I can’t figure out what I’m missing here.
Here’s a snippet of my server code in main:
indexLoc := os.Genenv(webRootEnv) + "/index.html" // verified this is the correct path to my static index.html file by logging it out
fs := http.FileServer(http.Dir(indexLoc))
http.ListenAndServe(":8080", nil)
http.Handle("/", fs)
Anyone have any ideas what I’m missing? Thanks in advance!

There are two things that could be the cause:
You're giving a file name to http.Dir, which expects a directory.
Your handler is registered after calling ListenAndServe, thus making it useless (http.Handle is never called)
You could fix it by changing your code like this:
indexLoc := os.Genenv(webRootEnv) // webRootEnv is a directory path
fs := http.FileServer(http.Dir(indexLoc))
http.Handle("/", fs) // register handler before listening
http.ListenAndServe(":8080", nil)
You might also want to handle the error returned from ListenAndServe to prevent silent failures of your program

Related

Zend framework ACL fails for the first time to switch the server

Hi guys!
I'm not native to English, so I'll appreciate if you correct my sentence!
To explain my issue, here is our development environment.
language : PHP7.3.11
framework : Zend framework v3.3.11
server : aws ec2×4
server OS : Amazonlinux 2
redis was enabled, there are two project like a-project/ec2×2(a-ec2) b-project/ec2×2(b-ec2)
the only differences between a-ec2 and b-ec2 are source code, the other setting like nginx, php-fpm, redis also DB setting are same.
if I lack some info, please let me know
When we joint these project, the problems happen.
After logged in our service, the zend works oddly.
the loginAction is on the a-ec2, we can successfully login with that.
And we save that session information on redis, and it works normally.
But only for the first time that we switch the server from a-ec2 to b-ec2, zend acl error has occur.
We use isAllowed function for checking the privilege for whether the user has enough privilege to access certain service.
The isAllowd function which located at line 827, /library/ZendAcl.php return false for the first time.
Then, we reload the page, the isAllowed function return true so that we can access to the service.
In detail, something went wrong around &_getRules function which is at line 1161, which is used _getRuleType function.
In those process, somehow one of the array contain "TYPE_DENY".
But when try to reload(ctrl + f5), that value turn into "TYPE_ALLOW".
How can this happen?
And how to fix this?
We are trying to figure this out like 2 weeks or more...
Thanks in advance!!
[update]
we found that this method which is written in under doesn't work well, so that we can't get $auth properly.
The $auth return "".
self::$_auth = $auth = Zend_Auth::getInstance()->getStorage()->read();
[update 2]
we might solve this issue, so I'll leave our solution.
we use
Zend_Auth::getInstance()->getStorage()->read()
to get $auth from session.
But for the first time, the session information which has saved at a-ec2 can't read at b-ec2.
So, we decided to use session information at redis, so we changed method to get $auth like
require_once 'Zend/Session.php';
Zend_Session::start();
self::$_auth = $auth = Common_Model_Redis::get();
start the session before connect to the redis server and just get session information form it!
I hope this will work you too!

How to get host name when testing using GAE?

When using the local development server, the port for my default service always defaults to 8080. However, when I use aetest, the port number always changes. The command used to start the local server when unit testing specifies --port=0. However, since this is in the app engine package, I do not want to modify it. I also can't specify the port number manually since tests are run using go test and not dev_appserver.py.
What I need
The code I am testing requires a particular response from a different microservice to continue execution successfully. To keep testing to this microservice, I am trying to set up a fake endpoint to provide me with the response I need.
Sample of code being tested
func Sample(c *gin.Context) {
...
url := os.Getenv("some_service") + "/some-endpoint"
req, err := http.NewRequest("POST", url, r.Body)
if err != nil {
// error handling
}
...
}
I need the host of the current service being tested to be able to set dummy environment variables for another microservice it interacts with. The host url should be the url of the service currently undergoing tests. This way I can use factory responses since I am not testing the other services in this set of tests.
What I've Tried
Using appengine.DefaultVersionHostname(), however this returns an empty string
Using the http request I create to get the url from that, however it does not include the host as needed (just the path)
Question
Is there any way to obtain the host for the local development server when running unit tests in GAE? Or, is there a way to specify the port number for app engine tests?
I was able to achieve my goal by first getting the list of modules. (It is likely the service name you are looking for will be default, however I chose to use the first name in the list anyways). Using the module name, I got the default version for the module. Using both of these (and an empty instance name), I was able to get the module host name which provided the value I was looking for.
A code sample is shown below:
ml, - := module.List(ctx)
mv, _ := module.DefaultVersion(ctx, ml[0])
hn, _ := appengine.ModuleHostname(ctx, ml[0], mv, "")
Thanks to Dan for pointing me in the right direction.

VSTS Load Test : Unable to stop running .css file

I did NOT see below request in my webtest, however it is being executed and failing.
I know this is a coding issue and it has to be fixed by development team , however I want to skip running this request for now and make my test pass. Please help me.
GTE https://www.corteva.com/etc/designs/default.css
Webtest:
Results:
You can set Parse Dependant Requests to false for corresponding request (e.g. https://www.corteva.com).
Ignore unimportant errors in web test

google api python client keeps using an old version of my local app engine endpoints

I have two python projects running locally:
A cloud endpoints python project using the latest App Engine version.
A client project which consumes the endpoint functions using the latest google-api-python-client (v 1.5.1).
Everything was fine until I renamed one endpoint's function from:
#endpoints.method(MyRequest, MyResponse, path = "save_ocupation", http_method='POST', name = "save_ocupation")
def save_ocupation(self, request):
[code here]
To:
#endpoints.method(MyRequest, MyResponse, path = "save_occupation", http_method='POST', name = "save_occupation")
def save_occupation(self, request):
[code here]
Looking at the local console (http://localhost:8080/_ah/api/explorer) I see the correct function name.
However, by executing the client project that invokes the endpoint, it keeps saying that the new endpoint function does not exist. I verified this using the ipython shell: The dynamically-generated python code for invoking the Resource has the old function name despite restarting both the server and client dozens of times.
How can I force the api client to get always the latest endpoint api document?
Help is appreciated.
Just after posting the question, I resumed my Ubuntu PC and started Eclipse and the python projects from scratch and now everything works as expected. This sounds like a kind of a http client cache, or a stale python process, which prevented from getting the latest discovery document and generating the corresponding resource code.
This is odd as I have tested running these projects outside and inside Eclipse without success. But I prefer documenting this just in case someone else has this issue.

can you view/tail the server log rails app on travis ci

I have Rails app which has an Rspec feature with selenium that always passes locally and periodically fails on travis. It fails on click_link("my link"), with a Net::ReadTimeout: error. The stack trace isn't all that helpful and It'd be nice if there was a way to tail the log (tail -f log/test.log), so see if that's helpful...or at least view the log output. Is this possible using travis ci? I'm already waiting for ajax to finish, which suggests something external, so ultimately I'm trying to find out what request it's getting hung up on.
I believe you can cat the logs to the console as the last step of your test task, or you can use Travis' artifact option to get them uploaded to S3 - see http://docs.travis-ci.com/user/uploading-artifacts/