Question:
App works but when i deploy the routes seem to not work any more.
Using Express, node,
do a post from postman to the route on the internal app works fine. Do the same for the deployed app . and i get a 404
Repl link/Link to where the bug appears:
Screenshots, links, or other helpful context:
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path'
import cors from 'cors';
import morgan from 'morgan';
import fileUpload from 'express-fileupload';
import multer from 'multer';
import OpenAI from 'openai';
import fs from 'fs';
import { generateResponse } from './lib/generateResponse.js';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const openai = new OpenAI(process.env.OPENAI_API_KEY);
//app.use(express.static('Public'));
app.use(express.static(path.join(__dirname, 'Public')));
app.use(bodyParser.json());
app.use(cors());
app.use(morgan('dev'));
app.post('/generateResponse', async (req, res) => {
console.log('generateResponse route hit');
const { prompt, history } = req.body;
const answer = await generateResponse({ prompt, history });
res.json({ answer });
const audioStream = await generateSpeech(answer);
//res.set('Content-Type', 'audio/mpeg');
audioStream.pipe(res); // Send the audio stre
});
app.get('/', (req, res) => {
res.sendFile(path.resolve('./Public/index.html')); // path.resolve is used to get absolute path
});