I have a Universal Javascript application deployed on Heroku.
In my setup, Express.js is loading my Vue.js app and proxying requests to https://localhost:3000/api
.
However, when I try to send a simple POST request to an endpoint, the Chrome console displays:
OPTIONS https://localhost:3000/api net::ERR_CONNECTION_CLOSED
Below is the code snippet for my express server:
import express from 'express'
import cors from 'cors'
import bodyParser from 'body-parser'
import path from 'path'
import mongoose from 'mongoose'
import routes from './routes'
mongoose.connect('mongodb://coolAddress');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
console.log("mongoose connected")
})
const app = express()
const port = 3000
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors())
app.use(express.static(path.resolve(__dirname, '../coolClient/dist')));
app.use('/api', routes)
app.all('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../coolClient/dist', 'index.html'));
})
app.listen(process.env.PORT || port, () => {
console.log(`App listening on ${process.env.PORT || port}`)
})
I suspect that the issue might be related to SSL configuration. While searching online, I found suggestions pointing towards SSL as a possible cause, but no clear solution has been provided.
Does anyone have any insights or ideas on how to troubleshoot this?