'400 error when trying to post song objects on deployed link
I've created an app with a vanilla JavaScript & OOJS frontend, and a Rails backend API.
One feature that worked in localhost is the ability to post a song. By "post a song", I don't mean posting the actual song, but posting string-type details about a song.
Posting songs worked in localhost but when I try it on my deployed Netlify link I get these console errors:
Failed to load resource: the server responded with a status of 400 (Bad Request)
index.js:73 Uncaught (in promise) SyntaxError: Unexpected end of input
at index.js:73:34
The unexpected end of input error points to .then((response) => response.json()) in my postFetch function below, and a red line underlines the json()) part:
function postFetch(name, artist, album, song_url, submitted_by, genre_id) {
const bodyData = { name, artist, album, song_url, submitted_by, genre_id }; //building body object outside of the fetch.
fetch("https://infinite-shore-27478.herokuapp.com/api/v1/songs", {
method: "POST",
mode: "no-cors",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(bodyData), //stringifying this json data in order to send it.
//here we are creating this object that we will send to our database based on attributes our api wants to create a new song
//this will send back the data to my api.
//the keys in our body data have to be exactly what they are like in the database.
})
.then((response) => response.json())
.then((song) => {
let newSong = new Song(song, song.data.attributes);
let songsContainer = document.querySelector("#song-container");
let songsContainerTitle = document.querySelector("#song-container-title");
songsContainer.innerHTML =
newSong.renderSongCard() + songsContainer.innerHTML;
handleLikes();
});
}
The headers from the network tab show the below after trying to post a song:
Request URL: https://infinite-shore-27478.herokuapp.com/api/v1/songs
Request Method: POST
Status Code: 400 Bad Request
Remote Address: 18.208.60.216:443
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin: https://song-sharer.netlify.app
Access-Control-Expose-Headers
Access-Control-Max-Age: 7200
Connection: keep-alive
Content-Length: 36
Content-Type: application/json; charset=UTF-8
Date: Fri, 11 Mar 2022 05:02:28 GMT
Server: Cowboy
Vary: Origin
Via: 1.1 vegur
X-Request-Id: 8928dc47-6842-4fb3-b1d7-2fdbc7ae6af9
X-Runtime: 0.001758
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 122
Content-Type: text/plain;charset=UTF-8
Host: infinite-shore-27478.herokuapp.com
Origin: https://song-sharer.netlify.app
Referer: https://song-sharer.netlify.app/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1
The payload tab shows what I inputted to create a song, as shown:
{name: "kafjkjafjk", artist: "dhafjhafjh", album: "dafklakf", song_url: "dfaakjk",…}
album: "dafklakf"
artist: "dhafjhafjh"
genre_id: 10
name: "kafjkjafjk"
song_url: "dfaakjk"
submitted_by: "djafkja"
My postFetch function above, which has code for posting a song, is initially called with values I get from the form inputs.
Earlier, I console.logged what response was in my postFetch function after trying to create a song- below was that output:
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}body: (...)bodyUsed: falseheaders: Headers {}ok: falseredirected: falsestatus: 0statusText: ""type: "opaque"url: ""[[Prototype]]: ResponsearrayBuffer: ƒ arrayBuffer()blob: ƒ blob()body: (...)bodyUsed: (...)clone: ƒ clone()formData: ƒ formData()headers: (...)json: ƒ json()ok: (...)redirected: (...)status: (...)statusText: (...)text: ƒ text()type: (...)url: (...)constructor: ƒ Response()Symbol(Symbol.toStringTag): "Response"get body: ƒ body()get bodyUsed: ƒ bodyUsed()get headers: ƒ headers()get ok: ƒ ok()get redirected: ƒ redirected()get status: ƒ status()get statusText: ƒ statusText()get type: ƒ type()get url: ƒ url()[[Prototype]]: Object
index.js:75 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
at index.js:75:41
It mentions (reading 'data'). I have .data.attributes on line 76 in my postFetch function because I used a serializer to shape song data so song objects are nested under a "data" key as shown below (this is how a song looks on my Heroku backend):
{
"data": {
"id": "15",
"type": "song",
"attributes": {
"name": "PBR&B VHS butcher park",
"artist": "credmaster",
"album": "Come On Over",
"song_url": "http://lockman-bahringer.info/shalanda.treutel",
"submitted_by": "Donnell O'Hara Sr.",
"genre_id": 42,
"genre": {
"id": 42,
"name": "Rock",
"description": "Thundercats cleanse selvage photo booth direct trade tumblr. Yuccie readymade knausgaard art party scenester portland tumblr iphone.",
"created_at": "2022-02-18T05:33:16.652Z",
"updated_at": "2022-02-18T05:33:16.652Z"
},
"likes": [
{
"id": 61,
"song_id": 15,
"created_at": "2022-02-18T05:34:59.276Z",
"updated_at": "2022-02-18T05:34:59.276Z"
}
]
}
}
}
Cors.rb file:
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "https://song-sharer.netlify.app"
resource "*", #can specify which resources we want to allow requests to be made of
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
Below are heroku logs that show on my backend application while my netlify frontend is running. There's a routing error, so maybe I need to change my routing? (FYI, I built this app to be a single page application):
2022-03-04T02:37:27.090460+00:00 app[web.1]: D, [2022-03-04T02:37:27.090381 #4] DEBUG -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] CACHE Genre Load (0.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T02:37:27.093749+00:00 app[web.1]: D, [2022-03-04T02:37:27.093690 #4] DEBUG -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] Genre Load (2.7ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 47], ["LIMIT", 1]]
2022-03-04T02:37:27.168298+00:00 app[web.1]: D, [2022-03-04T02:37:27.168195 #4] DEBUG -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] Like Load (67.9ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 15]]
2022-03-04T02:37:27.191944+00:00 app[web.1]: D, [2022-03-04T02:37:27.191836 #4] DEBUG -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] Like Load (6.3ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 14]]
2022-03-04T02:37:27.196168+00:00 app[web.1]: D, [2022-03-04T02:37:27.196078 #4] DEBUG -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] Like Load (3.1ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 13]]
2022-03-04T02:37:27.197107+00:00 app[web.1]: I, [2022-03-04T02:37:27.197054 #4] INFO -- : [28e28da3-8bbe-4f65-8883-f130aa3de302] Completed 200 OK in 3766ms (Views: 63.6ms | ActiveRecord: 3533.2ms | Allocations: 19861)
2022-03-04T02:37:27.199618+00:00 heroku[router]: at=info method=GET path="/api/v1/songs" host=infinite-shore-27478.herokuapp.com request_id=28e28da3-8bbe-4f65-8883-f130aa3de302 fwd="3.236.125.76" dyno=web.1 connect=0ms service=3771ms status=200 bytes=2200 protocol=https
2022-03-04T03:03:04.219876+00:00 app[web.1]: I, [2022-03-04T03:03:04.219781 #4] INFO -- : [67c20725-2083-41fb-aad3-e8faa556004c] Started HEAD "/api/v1/songs" for 217.182.175.162 at 2022-03-04 03:03:04 +0000
2022-03-04T03:03:04.220976+00:00 app[web.1]: I, [2022-03-04T03:03:04.220916 #4] INFO -- : [67c20725-2083-41fb-aad3-e8faa556004c] Processing by Api::V1::SongsController#index as HTML
2022-03-04T03:03:06.590407+00:00 app[web.1]: D, [2022-03-04T03:03:06.590295 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Song Load (437.7ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."created_at" DESC
2022-03-04T03:03:06.792388+00:00 app[web.1]: D, [2022-03-04T03:03:06.792273 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Genre Load (146.3ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T03:03:06.793700+00:00 app[web.1]: D, [2022-03-04T03:03:06.793637 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] CACHE Genre Load (0.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T03:03:06.797427+00:00 app[web.1]: D, [2022-03-04T03:03:06.797372 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Genre Load (2.9ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 47], ["LIMIT", 1]]
2022-03-04T03:03:06.885016+00:00 app[web.1]: D, [2022-03-04T03:03:06.884918 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Like Load (85.2ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 15]]
2022-03-04T03:03:06.887583+00:00 app[web.1]: D, [2022-03-04T03:03:06.887506 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Like Load (1.2ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 14]]
2022-03-04T03:03:06.889621+00:00 app[web.1]: D, [2022-03-04T03:03:06.889561 #4] DEBUG -- : [67c20725-2083-41fb-aad3-e8faa556004c] Like Load (1.0ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 13]]
2022-03-04T03:03:06.890439+00:00 app[web.1]: I, [2022-03-04T03:03:06.890392 #4] INFO -- : [67c20725-2083-41fb-aad3-e8faa556004c] Completed 200 OK in 2669ms (Views: 62.6ms | ActiveRecord: 2557.8ms | Allocations: 4723)
2022-03-04T03:03:06.892631+00:00 heroku[router]: at=info method=HEAD path="/api/v1/songs" host=infinite-shore-27478.herokuapp.com request_id=67c20725-2083-41fb-aad3-e8faa556004c fwd="217.182.175.162" dyno=web.1 connect=0ms service=2676ms status=200 bytes=482 protocol=https
2022-03-04T03:07:21.628891+00:00 app[web.1]: I, [2022-03-04T03:07:21.628820 #4] INFO -- : [e118c856-d94a-40a4-b92b-2f032b56506f] Started GET "/" for 64.98.23.82 at 2022-03-04 03:07:21 +0000
2022-03-04T03:07:21.630308+00:00 app[web.1]: F, [2022-03-04T03:07:21.630249 #4] FATAL -- : [e118c856-d94a-40a4-b92b-2f032b56506f]
2022-03-04T03:07:21.630309+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] ActionController::RoutingError (No route matches [GET] "/"):
2022-03-04T03:07:21.630318+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f]
2022-03-04T03:07:21.630319+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
2022-03-04T03:07:21.630319+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2022-03-04T03:07:21.630319+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] railties (6.0.4.6) lib/rails/rack/logger.rb:37:in `call_app'
2022-03-04T03:07:21.630320+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] railties (6.0.4.6) lib/rails/rack/logger.rb:26:in `block in call'
2022-03-04T03:07:21.630320+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:80:in `block in tagged'
2022-03-04T03:07:21.630321+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:28:in `tagged'
2022-03-04T03:07:21.630321+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] activesupport (6.0.4.6) lib/active_support/tagged_logging.rb:80:in `tagged'
2022-03-04T03:07:21.630322+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] railties (6.0.4.6) lib/rails/rack/logger.rb:26:in `call'
2022-03-04T03:07:21.630322+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2022-03-04T03:07:21.630322+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/request_id.rb:27:in `call'
2022-03-04T03:07:21.630323+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] rack (2.2.3) lib/rack/runtime.rb:22:in `call'
2022-03-04T03:07:21.630324+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] activesupport (6.0.4.6) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2022-03-04T03:07:21.630324+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
2022-03-04T03:07:21.630324+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/static.rb:126:in `call'
2022-03-04T03:07:21.630325+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
2022-03-04T03:07:21.630325+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] actionpack (6.0.4.6) lib/action_dispatch/middleware/host_authorization.rb:97:in `call'
2022-03-04T03:07:21.630325+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
2022-03-04T03:07:21.630326+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] railties (6.0.4.6) lib/rails/engine.rb:527:in `call'
2022-03-04T03:07:21.630326+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] puma (4.3.11) lib/puma/configuration.rb:228:in `call'
2022-03-04T03:07:21.630326+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] puma (4.3.11) lib/puma/server.rb:718:in `handle_request'
2022-03-04T03:07:21.630326+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] puma (4.3.11) lib/puma/server.rb:472:in `process_client'
2022-03-04T03:07:21.630327+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] puma (4.3.11) lib/puma/server.rb:328:in `block in run'
2022-03-04T03:07:21.630327+00:00 app[web.1]: [e118c856-d94a-40a4-b92b-2f032b56506f] puma (4.3.11) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
2022-03-04T03:07:21.631993+00:00 heroku[router]: at=info method=GET path="/" host=infinite-shore-27478.herokuapp.com request_id=e118c856-d94a-40a4-b92b-2f032b56506f fwd="64.98.23.82" dyno=web.1 connect=0ms service=6ms status=404 bytes=191 protocol=https
2022-03-04T03:07:23.944074+00:00 app[web.1]: I, [2022-03-04T03:07:23.943990 #4] INFO -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Started GET "/api/v1/songs" for 64.98.23.82 at 2022-03-04 03:07:23 +0000
2022-03-04T03:07:23.944708+00:00 app[web.1]: I, [2022-03-04T03:07:23.944649 #4] INFO -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Processing by Api::V1::SongsController#index as HTML
2022-03-04T03:07:23.954785+00:00 app[web.1]: D, [2022-03-04T03:07:23.954694 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Song Load (2.5ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."created_at" DESC
2022-03-04T03:07:23.960243+00:00 app[web.1]: D, [2022-03-04T03:07:23.960147 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Genre Load (4.2ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T03:07:23.961510+00:00 app[web.1]: D, [2022-03-04T03:07:23.961447 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] CACHE Genre Load (0.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T03:07:23.964127+00:00 app[web.1]: D, [2022-03-04T03:07:23.964070 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Genre Load (1.7ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 47], ["LIMIT", 1]]
2022-03-04T03:07:23.968157+00:00 app[web.1]: D, [2022-03-04T03:07:23.968084 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Like Load (3.0ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 15]]
2022-03-04T03:07:23.974290+00:00 app[web.1]: D, [2022-03-04T03:07:23.974212 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Like Load (5.0ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 14]]
2022-03-04T03:07:23.980241+00:00 app[web.1]: D, [2022-03-04T03:07:23.980157 #4] DEBUG -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Like Load (4.9ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 13]]
2022-03-04T03:07:23.980999+00:00 app[web.1]: I, [2022-03-04T03:07:23.980937 #4] INFO -- : [9acfffb1-adba-45ad-ae4b-8c022c691685] Completed 200 OK in 36ms (Views: 7.9ms | ActiveRecord: 21.3ms | Allocations: 2677)
2022-03-04T03:07:23.981315+00:00 heroku[router]: at=info method=GET path="/api/v1/songs" host=infinite-shore-27478.herokuapp.com request_id=9acfffb1-adba-45ad-ae4b-8c022c691685 fwd="64.98.23.82" dyno=web.1 connect=0ms service=41ms status=304 bytes=445 protocol=https
2022-03-04T03:42:33.522017+00:00 heroku[web.1]: Idling
2022-03-04T03:42:33.525764+00:00 heroku[web.1]: State changed from up to down
2022-03-04T03:42:34.973340+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-03-04T03:42:35.117577+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2022-03-04T03:42:35.119547+00:00 app[web.1]: === puma shutdown: 2022-03-04 03:42:35 +0000 ===
2022-03-04T03:42:35.119579+00:00 app[web.1]: - Goodbye!
2022-03-04T03:42:35.119754+00:00 app[web.1]: Exiting
2022-03-04T03:42:35.718656+00:00 heroku[web.1]: Process exited with status 143
2022-03-04T05:07:30.558646+00:00 heroku[web.1]: Unidling
2022-03-04T05:07:30.781692+00:00 heroku[web.1]: State changed from down to starting
2022-03-04T05:07:33.274932+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production`
2022-03-04T05:07:36.067557+00:00 app[web.1]: => Booting Puma
2022-03-04T05:07:36.067566+00:00 app[web.1]: => Rails 6.0.4.6 application starting in production
2022-03-04T05:07:36.067567+00:00 app[web.1]: => Run `rails server --help` for more startup options
2022-03-04T05:07:38.262213+00:00 app[web.1]: Puma starting in single mode...
2022-03-04T05:07:38.262247+00:00 app[web.1]: * Version 4.3.11 (ruby 2.6.1-p33), codename: Mysterious Traveller
2022-03-04T05:07:38.262248+00:00 app[web.1]: * Min threads: 5, max threads: 5
2022-03-04T05:07:38.262249+00:00 app[web.1]: * Environment: production
2022-03-04T05:07:38.262408+00:00 app[web.1]: * Listening on tcp://0.0.0.0:46422
2022-03-04T05:07:38.263131+00:00 app[web.1]: Use Ctrl-C to stop
2022-03-04T05:07:38.322992+00:00 heroku[web.1]: State changed from starting to up
2022-03-04T05:07:38.861981+00:00 app[web.1]: I, [2022-03-04T05:07:38.861918 #4] INFO -- : [f0f91d4f-156a-401e-8340-200f132b9431] Started GET "/api/v1/songs" for 64.98.23.82 at 2022-03-04 05:07:38 +0000
2022-03-04T05:07:38.863404+00:00 app[web.1]: I, [2022-03-04T05:07:38.863342 #4] INFO -- : [f0f91d4f-156a-401e-8340-200f132b9431] Processing by Api::V1::SongsController#index as */*
2022-03-04T05:07:39.139556+00:00 app[web.1]: D, [2022-03-04T05:07:39.139476 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Song Load (4.2ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."created_at" DESC
2022-03-04T05:07:39.194889+00:00 app[web.1]: D, [2022-03-04T05:07:39.194815 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Genre Load (2.8ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T05:07:39.198747+00:00 app[web.1]: D, [2022-03-04T05:07:39.198686 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] CACHE Genre Load (0.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T05:07:39.200119+00:00 app[web.1]: D, [2022-03-04T05:07:39.200078 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Genre Load (0.9ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 47], ["LIMIT", 1]]
2022-03-04T05:07:39.207834+00:00 app[web.1]: D, [2022-03-04T05:07:39.207790 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Like Load (2.6ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 15]]
2022-03-04T05:07:39.215511+00:00 app[web.1]: D, [2022-03-04T05:07:39.215459 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Like Load (0.9ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 14]]
2022-03-04T05:07:39.219415+00:00 app[web.1]: D, [2022-03-04T05:07:39.219375 #4] DEBUG -- : [f0f91d4f-156a-401e-8340-200f132b9431] Like Load (3.4ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 13]]
2022-03-04T05:07:39.219923+00:00 app[web.1]: I, [2022-03-04T05:07:39.219888 #4] INFO -- : [f0f91d4f-156a-401e-8340-200f132b9431] Completed 200 OK in 356ms (Views: 20.5ms | ActiveRecord: 225.0ms | Allocations: 19858)
2022-03-04T05:07:39.222382+00:00 heroku[router]: at=info method=GET path="/api/v1/songs" host=infinite-shore-27478.herokuapp.com request_id=f0f91d4f-156a-401e-8340-200f132b9431 fwd="64.98.23.82" dyno=web.1 connect=0ms service=359ms status=304 bytes=646 protocol=https
2022-03-04T05:07:40.144204+00:00 app[web.1]: I, [2022-03-04T05:07:40.144136 #4] INFO -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Started GET "/api/v1/songs" for 64.98.23.82 at 2022-03-04 05:07:40 +0000
2022-03-04T05:07:40.144706+00:00 app[web.1]: I, [2022-03-04T05:07:40.144669 #4] INFO -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Processing by Api::V1::SongsController#index as */*
2022-03-04T05:07:40.147913+00:00 app[web.1]: D, [2022-03-04T05:07:40.147856 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Song Load (1.1ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."created_at" DESC
2022-03-04T05:07:40.163717+00:00 app[web.1]: D, [2022-03-04T05:07:40.163644 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Genre Load (15.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T05:07:40.164485+00:00 app[web.1]: D, [2022-03-04T05:07:40.164432 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] CACHE Genre Load (0.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
2022-03-04T05:07:40.165897+00:00 app[web.1]: D, [2022-03-04T05:07:40.165842 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Genre Load (1.0ms) SELECT "genres".* FROM "genres" WHERE "genres"."id" = $1 LIMIT $2 [["id", 47], ["LIMIT", 1]]
2022-03-04T05:07:40.167511+00:00 app[web.1]: D, [2022-03-04T05:07:40.167467 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Like Load (1.0ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 15]]
2022-03-04T05:07:40.169013+00:00 app[web.1]: D, [2022-03-04T05:07:40.168972 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Like Load (0.9ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 14]]
2022-03-04T05:07:40.171442+00:00 app[web.1]: D, [2022-03-04T05:07:40.171395 #4] DEBUG -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Like Load (2.0ms) SELECT "likes".* FROM "likes" WHERE "likes"."song_id" = $1 [["song_id", 13]]
2022-03-04T05:07:40.171882+00:00 app[web.1]: I, [2022-03-04T05:07:40.171849 #4] INFO -- : [475cac01-83a6-42e8-8feb-1baf28dfb25d] Completed 200 OK in 27ms (Views: 4.5ms | ActiveRecord: 20.9ms | Allocations: 2678)
2022-03-04T05:07:40.174990+00:00 heroku[router]: at=info method=GET path="/api/v1/songs" host=infinite-shore-27478.herokuapp.com request_id=475cac01-83a6-42e8-8feb-1baf28dfb25d fwd="64.98.23.82" dyno=web.1 connect=0ms service=29ms status=200 bytes=2401 protocol=https
Config/routes.rb:
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
namespace :api do
namespace :v1 do #gives us version control for multiple apis we might want to have
resources :songs, only: [:index, :create, :show] #since building vertically only going to focus on index for now.
resources :genres, only: [:index]
resources :likes
end
end
end
Not sure why I have the above errors and why my response from my post fetch isn't coming through.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
