Build sucessful but Cannot GET /

Hello everyone ,

I have deployed a full stack application, the deploy seems successful but I get an error saying " Cannot GET / ". Link to the website https://twitterapp-nfle.onrender.com/ link to my repo – https://github.com/Ris345/Twitter-Showcase-Ap . I would really appreciate any help thank you!

Hey there.

What is your build command and start command in render settings for this app?

Since you have both back-end and your front-end in the same app you need to make sure you build both. Does this work locally?

My guess is that on your computer/locally you are starting two servers: The react dev server and nodmon. Neither should be used in production.

You have two options.

A) Serve the react files with your expressjs server.

  1. Build the front-end so that you get a build or dist folder with your react front-end.
  2. Serve that in your express app, something like app.use('/', express.static('dist')) so that index.html is served and all the js bundle with it.

B) Split it up into to render projects.

  1. Static site: Build the front and and use static site here on render to deploy and serve it.
  2. Web service: Only the nodejs code.

Thanks for the reply, yes my app does run locally. I am running my front-end and back-end concurrently, while I am proxying the back-end server to 3001. My build command is npm install.

Hi there,

The repo link 404s for me, maybe you made it private? Also you’ve not really provided much information on your set up. Bergur’s suggestions are valid, but you’ve only mentioned your Build Command.

You’ll need to share more details if you require further assistance. If you don’t want to share these details on the community forum, please feel free to raise a ticket from the “Contact Support” link at the bottom of the Dashboard.

Alan

Thank you for the reply here is my repo the link didn’t get copied perfectly. Repo .
I am deploying a full stack application, the back-end is node.js and the front-end is reactjs. I have tried the second method @bergur suggested, but I haven’t had any luck.
The setup: I am using npm install as my build command. I am using node/back-end.js as my start command and using auto deploy option from the main branch. Hope that clarifies things.

The error I am seeing in my build log is this :

Jan 4 05:59:08 PM  AxiosError: Request failed with status code 401
Jan 4 05:59:08 PM      at settle (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:1268:12)
Jan 4 05:59:08 PM      at IncomingMessage.handleStreamEnd (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:2446:11)
Jan 4 05:59:08 PM      at IncomingMessage.emit (events.js:388:22)
Jan 4 05:59:08 PM      at endReadableNT (internal/streams/readable.js:1336:12)
Jan 4 05:59:08 PM      at processTicksAndRejections (internal/process/task_queues.js:82:21) ```

Things run locally but it shows this error in my build logs.

For anyone to be able to help, they need details. Logs, URLs, screenshots, something to go off. Build Commands and Auto-Deploys don’t really help when your original issue you started occurs after the deploy is successful.

Cannot GET / is Express telling you a root path route isn’t defined, so what is the Start Command? (and if it’s npm start share the start script from the package.json).

Alan

My start command is node back-end/app.js
My start script in the parent directory is

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "concurrently \"npm run start --prefix front-end\" \"npm run start --prefix back-end\"",
    "start": "concurrently \"npm run start --prefix front-end\" \"npm run start --prefix back-end\"",
    "build": "concurrently \"npm run start --prefix front-end\" \"npm run start --prefix back-end\""
  },

here is some of the build log

Jan 4 01:11:47 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:11:50 PM  valid repsonse on port 3001
Jan 4 01:12:07 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:12:09 PM  valid repsonse on port 3001
Jan 4 01:29:30 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:29:32 PM  valid repsonse on port 3001
Jan 4 01:29:51 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:29:53 PM  valid repsonse on port 3001
Jan 4 01:34:06 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:34:07 PM  valid repsonse on port 3001
Jan 4 01:34:10 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 01:34:12 PM  valid repsonse on port 3001
Jan 4 02:08:25 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 02:08:27 PM  valid repsonse on port 3001
Jan 4 05:51:39 PM  ==> Starting service with 'node back-end/app.js '
Jan 4 05:51:40 PM  valid repsonse on port 3001
Jan 4 05:59:08 PM  AxiosError: Request failed with status code 401
Jan 4 05:59:08 PM      at settle (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:1268:12)
Jan 4 05:59:08 PM      at IncomingMessage.handleStreamEnd (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:2446:11)
Jan 4 05:59:08 PM      at IncomingMessage.emit (events.js:388:22)
Jan 4 05:59:08 PM      at endReadableNT (internal/streams/readable.js:1336:12)
Jan 4 05:59:08 PM      at processTicksAndRejections (internal/process/task_queues.js:82:21) {
Jan 4 05:59:08 PM    code: 'ERR_BAD_REQUEST',
Jan 4 05:59:08 PM    config: {
Jan 4 05:59:08 PM      transitional: {
Jan 4 05:59:08 PM        silentJSONParsing: true,
Jan 4 05:59:08 PM        forcedJSONParsing: true,
Jan 4 05:59:08 PM        clarifyTimeoutError: false
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      adapter: [Function: httpAdapter],
Jan 4 05:59:08 PM      transformRequest: [ [Function: transformRequest] ],
Jan 4 05:59:08 PM      transformResponse: [ [Function: transformResponse] ],
Jan 4 05:59:08 PM      timeout: 0,
Jan 4 05:59:08 PM      xsrfCookieName: 'XSRF-TOKEN',
Jan 4 05:59:08 PM      xsrfHeaderName: 'X-XSRF-TOKEN',
Jan 4 05:59:08 PM      maxContentLength: -1,
Jan 4 05:59:08 PM      maxBodyLength: -1,
Jan 4 05:59:08 PM      env: { FormData: [Function], Blob: null },
Jan 4 05:59:08 PM      validateStatus: [Function: validateStatus],
Jan 4 05:59:08 PM      headers: AxiosHeaders {
Jan 4 05:59:08 PM        authorization: 'Bearer undefined',
Jan 4 05:59:08 PM        'User-Agent': 'axios/1.1.3',
Jan 4 05:59:08 PM        'Accept-Encoding': 'gzip, deflate, br',
Jan 4 05:59:08 PM        [Symbol(defaults)]: [Object]
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      method: 'get',
Jan 4 05:59:08 PM      url: 'https://api.twitter.com/2/users/undefined/tweets?tweet.fields=public_metrics&expansions=attachments.media_keys,author_id&media.fields=duration_ms,height,media_key,preview_image_url,url&user.fields=description,profile_image_url',
Jan 4 05:59:08 PM      data: undefined
Jan 4 05:59:08 PM    },
Jan 4 05:59:08 PM    request: <ref *1> ClientRequest {
Jan 4 05:59:08 PM      _events: [Object: null prototype] {
Jan 4 05:59:08 PM        abort: [Function (anonymous)],
Jan 4 05:59:08 PM        aborted: [Function (anonymous)],
Jan 4 05:59:08 PM        connect: [Function (anonymous)],
Jan 4 05:59:08 PM        error: [Function (anonymous)],
Jan 4 05:59:08 PM        socket: [Function (anonymous)],
Jan 4 05:59:08 PM        timeout: [Function (anonymous)],
Jan 4 05:59:08 PM        prefinish: [Function: requestOnPrefinish]
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      _eventsCount: 7,
Jan 4 05:59:08 PM      _maxListeners: undefined,
Jan 4 05:59:08 PM      outputData: [],
Jan 4 05:59:08 PM      outputSize: 0,
Jan 4 05:59:08 PM      writable: true,
Jan 4 05:59:08 PM      destroyed: false,
Jan 4 05:59:08 PM      _last: true,
Jan 4 05:59:08 PM      chunkedEncoding: false,
Jan 4 05:59:08 PM      shouldKeepAlive: false,
Jan 4 05:59:08 PM      _defaultKeepAlive: true,
Jan 4 05:59:08 PM      useChunkedEncodingByDefault: false,
Jan 4 05:59:08 PM      sendDate: false,
Jan 4 05:59:08 PM      _removedConnection: false,
Jan 4 05:59:08 PM      _removedContLen: false,
Jan 4 05:59:08 PM      _removedTE: false,
Jan 4 05:59:08 PM      _contentLength: 0,
Jan 4 05:59:08 PM      _hasBody: true,
Jan 4 05:59:08 PM      _trailer: '',
Jan 4 05:59:08 PM      finished: true,
Jan 4 05:59:08 PM      _headerSent: true,
Jan 4 05:59:08 PM      socket: TLSSocket {
Jan 4 05:59:08 PM        _tlsOptions: [Object],
Jan 4 05:59:08 PM        _secureEstablished: true,
Jan 4 05:59:08 PM        _securePending: false,
Jan 4 05:59:08 PM        _newSessionPending: false,
Jan 4 05:59:08 PM        _controlReleased: true,
Jan 4 05:59:08 PM        secureConnecting: false,
Jan 4 05:59:08 PM        _SNICallback: null,
Jan 4 05:59:08 PM        servername: 'api.twitter.com',
Jan 4 05:59:08 PM        alpnProtocol: false,
Jan 4 05:59:08 PM        authorized: true,
Jan 4 05:59:08 PM        authorizationError: null,
Jan 4 05:59:08 PM        encrypted: true,
Jan 4 05:59:08 PM        _events: [Object: null prototype],
Jan 4 05:59:08 PM        _eventsCount: 10,
Jan 4 05:59:08 PM        connecting: false,
Jan 4 05:59:08 PM        _hadError: false,
Jan 4 05:59:08 PM        _parent: null,
Jan 4 05:59:08 PM        _host: 'api.twitter.com',
Jan 4 05:59:08 PM        _readableState: [ReadableState],
Jan 4 05:59:08 PM        _maxListeners: undefined,
Jan 4 05:59:08 PM        _writableState: [WritableState],
Jan 4 05:59:08 PM        allowHalfOpen: false,
Jan 4 05:59:08 PM        _sockname: null,
Jan 4 05:59:08 PM        _pendingData: null,
Jan 4 05:59:08 PM        _pendingEncoding: '',
Jan 4 05:59:08 PM        server: undefined,
Jan 4 05:59:08 PM        _server: null,
Jan 4 05:59:08 PM        ssl: [TLSWrap],
Jan 4 05:59:08 PM        _requestCert: true,
Jan 4 05:59:08 PM        _rejectUnauthorized: true,
Jan 4 05:59:08 PM        parser: null,
Jan 4 05:59:08 PM        _httpMessage: [Circular *1],
Jan 4 05:59:08 PM        [Symbol(res)]: [TLSWrap],
Jan 4 05:59:08 PM        [Symbol(verified)]: true,
Jan 4 05:59:08 PM        [Symbol(pendingSession)]: null,
Jan 4 05:59:08 PM        [Symbol(async_id_symbol)]: 913,
Jan 4 05:59:08 PM        [Symbol(kHandle)]: [TLSWrap],
Jan 4 05:59:08 PM        [Symbol(kSetNoDelay)]: false,
Jan 4 05:59:08 PM        [Symbol(lastWriteQueueSize)]: 0,
Jan 4 05:59:08 PM        [Symbol(timeout)]: null,
Jan 4 05:59:08 PM        [Symbol(kBuffer)]: null,
Jan 4 05:59:08 PM        [Symbol(kBufferCb)]: null,
Jan 4 05:59:08 PM        [Symbol(kBufferGen)]: null,
Jan 4 05:59:08 PM        [Symbol(kCapture)]: false,
Jan 4 05:59:08 PM        [Symbol(kBytesRead)]: 0,
Jan 4 05:59:08 PM        [Symbol(kBytesWritten)]: 0,
Jan 4 05:59:08 PM        [Symbol(connect-options)]: [Object],
Jan 4 05:59:08 PM        [Symbol(RequestTimeout)]: undefined
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      _header: 'GET /2/users/undefined/tweets?tweet.fields=public_metrics&expansions=attachments.media_keys,author_id&media.fields=duration_ms,height,media_key,preview_image_url,url&user.fields=description,profile_image_url HTTP/1.1\r\n' +
Jan 4 05:59:08 PM        'Accept: application/json, text/plain, */*\r\n' +
Jan 4 05:59:08 PM        'authorization: Bearer undefined\r\n' +
Jan 4 05:59:08 PM        'User-Agent: axios/1.1.3\r\n' +
Jan 4 05:59:08 PM        'Accept-Encoding: gzip, deflate, br\r\n' +
Jan 4 05:59:08 PM        'Host: api.twitter.com\r\n' +
Jan 4 05:59:08 PM        'Connection: close\r\n' +
Jan 4 05:59:08 PM        '\r\n',
Jan 4 05:59:08 PM      _keepAliveTimeout: 0,
Jan 4 05:59:08 PM      _onPendingData: [Function: noopPendingOutput],
Jan 4 05:59:08 PM      agent: Agent {
Jan 4 05:59:08 PM        _events: [Object: null prototype],
Jan 4 05:59:08 PM        _eventsCount: 2,
Jan 4 05:59:08 PM        _maxListeners: undefined,
Jan 4 05:59:08 PM        defaultPort: 443,
Jan 4 05:59:08 PM        protocol: 'https:',
Jan 4 05:59:08 PM        options: [Object],
Jan 4 05:59:08 PM        requests: {},
Jan 4 05:59:08 PM        sockets: [Object],
Jan 4 05:59:08 PM        freeSockets: {},
Jan 4 05:59:08 PM        keepAliveMsecs: 1000,
Jan 4 05:59:08 PM        keepAlive: false,
Jan 4 05:59:08 PM        maxSockets: Infinity,
Jan 4 05:59:08 PM        maxFreeSockets: 256,
Jan 4 05:59:08 PM        scheduling: 'lifo',
Jan 4 05:59:08 PM        maxTotalSockets: Infinity,
Jan 4 05:59:08 PM        totalSocketCount: 1,
Jan 4 05:59:08 PM        maxCachedSessions: 100,
Jan 4 05:59:08 PM        _sessionCache: [Object],
Jan 4 05:59:08 PM        [Symbol(kCapture)]: false
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      socketPath: undefined,
Jan 4 05:59:08 PM      method: 'GET',
Jan 4 05:59:08 PM      maxHeaderSize: undefined,
Jan 4 05:59:08 PM      insecureHTTPParser: undefined,
Jan 4 05:59:08 PM      path: '/2/users/undefined/tweets?tweet.fields=public_metrics&expansions=attachments.media_keys,author_id&media.fields=duration_ms,height,media_key,preview_image_url,url&user.fields=description,profile_image_url',
Jan 4 05:59:08 PM      _ended: true,
Jan 4 05:59:08 PM      res: IncomingMessage {
Jan 4 05:59:08 PM        _readableState: [ReadableState],
Jan 4 05:59:08 PM        _events: [Object: null prototype],
Jan 4 05:59:08 PM        _eventsCount: 4,
Jan 4 05:59:08 PM        _maxListeners: undefined,
Jan 4 05:59:08 PM        socket: [TLSSocket],
Jan 4 05:59:08 PM        httpVersionMajor: 1,
Jan 4 05:59:08 PM        httpVersionMinor: 1,
Jan 4 05:59:08 PM        httpVersion: '1.1',
Jan 4 05:59:08 PM        complete: true,
Jan 4 05:59:08 PM        headers: [Object],
Jan 4 05:59:08 PM        rawHeaders: [Array],
Jan 4 05:59:08 PM        trailers: {},
Jan 4 05:59:08 PM        rawTrailers: [],
Jan 4 05:59:08 PM        aborted: false,
Jan 4 05:59:08 PM        upgrade: false,
Jan 4 05:59:08 PM        url: '',
Jan 4 05:59:08 PM        method: null,
Jan 4 05:59:08 PM        statusCode: 401,
Jan 4 05:59:08 PM        statusMessage: 'Unauthorized',
Jan 4 05:59:08 PM        client: [TLSSocket],
Jan 4 05:59:08 PM        _consuming: false,
Jan 4 05:59:08 PM        _dumped: false,
Jan 4 05:59:08 PM        req: [Circular *1],
Jan 4 05:59:08 PM        responseUrl: 'https://api.twitter.com/2/users/undefined/tweets?tweet.fields=public_metrics&expansions=attachments.media_keys,author_id&media.fields=duration_ms,height,media_key,preview_image_url,url&user.fields=description,profile_image_url',
Jan 4 05:59:08 PM        redirects: [],
Jan 4 05:59:08 PM        [Symbol(kCapture)]: false,
Jan 4 05:59:08 PM        [Symbol(RequestTimeout)]: undefined
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      aborted: false,
Jan 4 05:59:08 PM      timeoutCb: null,
Jan 4 05:59:08 PM      upgradeOrConnect: false,
Jan 4 05:59:08 PM      parser: null,
Jan 4 05:59:08 PM      maxHeadersCount: null,
Jan 4 05:59:08 PM      reusedSocket: false,
Jan 4 05:59:08 PM      host: 'api.twitter.com',
Jan 4 05:59:08 PM      protocol: 'https:',
Jan 4 05:59:08 PM      _redirectable: Writable {
Jan 4 05:59:08 PM        _writableState: [WritableState],
Jan 4 05:59:08 PM        _events: [Object: null prototype],
Jan 4 05:59:08 PM        _eventsCount: 3,
Jan 4 05:59:08 PM        _maxListeners: undefined,
Jan 4 05:59:08 PM        _options: [Object],
Jan 4 05:59:08 PM        _ended: true,
Jan 4 05:59:08 PM        _ending: true,
Jan 4 05:59:08 PM        _redirectCount: 0,
Jan 4 05:59:08 PM        _redirects: [],
Jan 4 05:59:08 PM        _requestBodyLength: 0,
Jan 4 05:59:08 PM        _requestBodyBuffers: [],
Jan 4 05:59:08 PM        _onNativeResponse: [Function (anonymous)],
Jan 4 05:59:08 PM        _currentRequest: [Circular *1],
Jan 4 05:59:08 PM        _currentUrl: 'https://api.twitter.com/2/users/undefined/tweets?tweet.fields=public_metrics&expansions=attachments.media_keys,author_id&media.fields=duration_ms,height,media_key,preview_image_url,url&user.fields=description,profile_image_url',
Jan 4 05:59:08 PM        [Symbol(kCapture)]: false
Jan 4 05:59:08 PM      },
Jan 4 05:59:08 PM      [Symbol(kCapture)]: false,
Jan 4 05:59:08 PM      [Symbol(kNeedDrain)]: false,
Jan 4 05:59:08 PM      [Symbol(corked)]: 0,
Jan 4 05:59:08 PM      [Symbol(kOutHeaders)]: [Object: null prototype] {
Jan 4 05:59:08 PM        accept: [Array],
Jan 4 05:59:08 PM        authorization: [Array],
Jan 4 05:59:08 PM        'user-agent': [Array],
Jan 4 05:59:08 PM        'accept-encoding': [Array],
Jan 4 05:59:08 PM        host: [Array]
Jan 4 05:59:08 PM      }
Jan 4 05:59:08 PM    },
Jan 4 05:59:08 PM    response: {
Jan 4 05:59:08 PM      status: 401,
Jan 4 05:59:08 PM      statusText: 'Unauthorized',
Jan 4 05:59:08 PM      headers: AxiosHeaders {
Jan 4 05:59:08 PM        perf: '7626143928',
Jan 4 05:59:08 PM        'content-type': 'application/problem+json',
Jan 4 05:59:08 PM        'cache-control': 'no-cache, no-store, max-age=0',
Jan 4 05:59:08 PM        'content-length': '99',
Jan 4 05:59:08 PM        'x-transaction-id': 'ef35a7c0c9da4ae1',
Jan 4 05:59:08 PM        'x-response-time': '1',
Jan 4 05:59:08 PM        'x-connection-hash': 'e7b66498251b1198bbc05f2d7f367639e9822eca575861c1f9fdf63d21d4a871',
Jan 4 05:59:08 PM        date: 'Wed, 04 Jan 2023 22:59:08 GMT',
Jan 4 05:59:08 PM        server: 'tsa_p',
Jan 4 05:59:08 PM        connection: 'close',
Jan 4 05:59:08 PM        [Symbol(defaults)]: null
Jan 4 05:59:08 PM      },

Ok, so you need to try debugging your issue.

You know the root path shows Cannot GET /. So do other routes/paths work? Here’s another route:

app.get("/api/tweets", (req, res) => { ...

Yes, that works: https://twitterapp-nfle.onrender.com/api/tweets.

So move on to a root path declaration:

app.use('/', express.static('/build'))

Which shows the root path is used to reference static files. But the path /build is likely incorrect for the following reasons:

  • There’s no build folder in your repo, which is fine, but…
  • …you’re not doing any build scripts in your Build Command, just npm install (as you’ve mentioned).

Things to check:

Please note, this level of assistance is far beyond the scope of our support. This isn’t a Render issue and we can’t debug everyone’s code as every app, its implementation, and its intention is different. This is hopefully a starting point for you to try things, search the internet or maybe other community members may have more suggestions for you.

Alan

Thank you! I appreciate it