Question: When trying to deploy the PlayHT text-to-speech API, I get the following error in the Chrome browser console:
When I make the following 2 changes to address it, I get a 404 access “cannot GET /” error:
- Change 1: Create an index.js file as specified in this solution to the problem.
- Change 2: Modify the folder structure such that all client side files are in a folder call public (e.g. script.js, style.css, index.html), and the index.js is outside this public file in the root directory. Modify path references accordingly. Run node index.js
Any ideas on where I begin to debug? Have spent a day on this now
Repl link:
https://replit.com/@IshaniM1/EdTech-Chat-InterfaceMobile
Code in the index.js file
const express = require("express");
const app = express();
const http = require("http");
const sockets = require("socket.io");
const cors = require("cors");
app.use(cors({
origin: "https://edtech-chat-interfacemobile.ishanim1.repl.co", // Update with your origin
methods: "GET",
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
}));
app.use(express.static("public"));
const server = http.createServer(app);
const io = sockets(server, {
cors: {
origin: "https://edtech-chat-interfacemobile.ishanim1.repl.co",
methods: ["GET", "POST"],
},
});
app.get("/api/connection-check", (req, res) => {
res.json({
server_status: "good",
});
});
app.get("/", (req, res) => {
// Send a response for the root route
res.sendFile(__dirname + "/public/index.html");
});
const port = process.env.PORT || 8080;
server.listen(port, function() {
console.log("Listening on port", port);
});