Home > Enterprise >  404 Not Found for index.html in Google App Engine - How to get page to show up?
404 Not Found for index.html in Google App Engine - How to get page to show up?

Time:10-11

I am trying to host my project with Google App Engine and I am unable to get my pages to show up. My package.json looks like this

  "name": "final",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "scripts": {
    "start": "node app.js"
}

My app.js looks like this :

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.sendFile('/index.html');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});

When I deploy, the page just says Not Found and gives me a 404. Is there something I need to do with my index.html and subsequent .js files it uses or is my entire directory uploaded whenever I deploy? Error logs give me nothing other than the 404.

CodePudding user response:

You need to specify the full path of index.html

const express = require('express');
const app = express();
const path = require('path');

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, '/index.html'));
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});
  • Related