If I build my .NET Core app from the solution directory on my windows dev machine like so:
dotnet publish --configuration Release --output \myproject --self-contained --runtime win7-x64
I can run this and hit my endpoint http://localhost:5000/api/auth/login
, no worries.
I do an almost identical publish to an ubuntu 18.04 LTS machine:
dotnet publish --configuration Release --output /ubuntu-myproject --self-contained --runtime ubuntu-x64
...copy the files up to the folder, set the proper project file to executable and run it, it starts listening on localhost:5000 just the same. Static pages (like my basic index.html) serve... but all my api endpoints are returning 404's. I'm scratching my head as to why this would be. There doesn't seem to be any error messages or anything, it's like the routes are just not registered or something.
Can someone clue me in as to why this might be the case?
This was built with .NET Core SDK 2.1.302.
UPDATE
I set the logging to debug and used a route that is known to be working everywhere but this linux machine: GET /api/groups
. I called this from the command line window on the linux machine:
curl -I http://localhost:5000/api/groups
my response was as such:
HTTP/1.1 404 Not Found
Date: Wed, 01 Aug 2018 02:15:48 GMT
Server: Kestrel
my log file had the following event info:
2018/08/01 02:15:49.241|INFO|Request starting HTTP/1.1 HEAD http://localhost:5000/api/groups |Microsoft.AspNetCore.Hosting.Internal.WebHost|Protocol=HTTP/1.1, Method=HEAD, ContentType=, ContentLength=, Scheme=http, Host=localhost:5000, PathBase=, Path=/api/groups, QueryString=, EventId_Id=1, EventId_Name=, EventId=1
2018/08/01 02:15:49.535|INFO|Request finished in 292.2005ms 404 |Microsoft.AspNetCore.Hosting.Internal.WebHost|ElapsedMilliseconds=292.2005, StatusCode=404, ContentType=, EventId_Id=2, EventId_Name=, EventId=2
So the problem here was actually 2 things. As @MarkG suggested, I was being led astray by my incorrect assumption of how to test an API endpoint with curl
. I should not have used the -I
parameter, it was sending the wrong request, hence I got a 404... in other words, instead of sending a GET /api/groups
request, I was sending a HEAD /api/groups
... which was not a defined route, and therefore should return a 404.
The second problem was that my nginx proxy was not properly configured, so externally all my /api/ endpoints were returning 404 as well, for a different reason. In combination with my bad curl requests, it seemed that nginx was properly configured, and my api service was simply returning 404's for everything... when in fact it was just me messing up at multiple levels.