admin管理员组

文章数量:1026190

I'm running a Universal Javascript application on Heroku.

My Vue.js app is being loaded by Express.js and requests are proxied to https://localhost:3000/api.

I am trying to make a simple POST request to an endpoint, however the console on Chrome prints out:

OPTIONS https://localhost:3000/api net::ERR_CONNECTION_CLOSED

Here is 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 this may have to do with SSL configuration. Googling the issue brings that possibility up, but doesn't provide much of an approach to debug it.

Any ideas?

I'm running a Universal Javascript application on Heroku.

My Vue.js app is being loaded by Express.js and requests are proxied to https://localhost:3000/api.

I am trying to make a simple POST request to an endpoint, however the console on Chrome prints out:

OPTIONS https://localhost:3000/api net::ERR_CONNECTION_CLOSED

Here is 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 this may have to do with SSL configuration. Googling the issue brings that possibility up, but doesn't provide much of an approach to debug it.

Any ideas?

Share Improve this question edited Jan 25, 2017 at 0:03 softcode asked Jan 24, 2017 at 23:30 softcodesoftcode 4,68812 gold badges44 silver badges69 bronze badges 8
  • Show some code if you want help, in particular your express app setup. – Paul Commented Jan 24, 2017 at 23:31
  • @Paul ok edited. Any ideas how to fix this ? – softcode Commented Jan 24, 2017 at 23:57
  • I'm still not fully clear on your architecture. Your app is on heroku, or it's on localhost? – Paul Commented Jan 24, 2017 at 23:58
  • @Paul Both my client app and API server are hosted on Heroku. The API server serves the client app itself – softcode Commented Jan 25, 2017 at 0:01
  • And the error is on the client or on the server? – Paul Commented Jan 25, 2017 at 0:01
 |  Show 3 more ments

2 Answers 2

Reset to default 0

Ok, so from the ments, a few things to look at.

1) "localhost" means your puter. If your client code is trying to hit that, it's going to need a server running on your machine and serving your server-side code. You absolutely need to have a web-accessible domain name (like the one heroku provided you: app-name.herokuapp.) to be able to hit your serverside code when it's hosted on heroku (or any other web host).

2) If you want to use HTTPS, then you have to buy and install an SSL certificate. It won't be for the herokuapp domain, so you'll also need to buy a domain name and set that up for yourself. All of that is explained on the heroku docs: https://devcenter.heroku./articles/ssl-endpoint

Hope that helps.

I figured out and ssl requests working like a charm on my Centos6.9

  • install virtualmin on your server
  • setup Lets encrypt
  • Just refer

before your call to
var app = express();
or any other http(s) mechanism or app.listen(port),

  var options = {
    key: fs.readFileSync('/home/yourdomain/ssl.key'),
    cert: fs.readFileSync('/home/domain/ssl.cert'),
  };

Note: you must take in to account about 'No Access control allow origin'

I'm running a Universal Javascript application on Heroku.

My Vue.js app is being loaded by Express.js and requests are proxied to https://localhost:3000/api.

I am trying to make a simple POST request to an endpoint, however the console on Chrome prints out:

OPTIONS https://localhost:3000/api net::ERR_CONNECTION_CLOSED

Here is 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 this may have to do with SSL configuration. Googling the issue brings that possibility up, but doesn't provide much of an approach to debug it.

Any ideas?

I'm running a Universal Javascript application on Heroku.

My Vue.js app is being loaded by Express.js and requests are proxied to https://localhost:3000/api.

I am trying to make a simple POST request to an endpoint, however the console on Chrome prints out:

OPTIONS https://localhost:3000/api net::ERR_CONNECTION_CLOSED

Here is 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 this may have to do with SSL configuration. Googling the issue brings that possibility up, but doesn't provide much of an approach to debug it.

Any ideas?

Share Improve this question edited Jan 25, 2017 at 0:03 softcode asked Jan 24, 2017 at 23:30 softcodesoftcode 4,68812 gold badges44 silver badges69 bronze badges 8
  • Show some code if you want help, in particular your express app setup. – Paul Commented Jan 24, 2017 at 23:31
  • @Paul ok edited. Any ideas how to fix this ? – softcode Commented Jan 24, 2017 at 23:57
  • I'm still not fully clear on your architecture. Your app is on heroku, or it's on localhost? – Paul Commented Jan 24, 2017 at 23:58
  • @Paul Both my client app and API server are hosted on Heroku. The API server serves the client app itself – softcode Commented Jan 25, 2017 at 0:01
  • And the error is on the client or on the server? – Paul Commented Jan 25, 2017 at 0:01
 |  Show 3 more ments

2 Answers 2

Reset to default 0

Ok, so from the ments, a few things to look at.

1) "localhost" means your puter. If your client code is trying to hit that, it's going to need a server running on your machine and serving your server-side code. You absolutely need to have a web-accessible domain name (like the one heroku provided you: app-name.herokuapp.) to be able to hit your serverside code when it's hosted on heroku (or any other web host).

2) If you want to use HTTPS, then you have to buy and install an SSL certificate. It won't be for the herokuapp domain, so you'll also need to buy a domain name and set that up for yourself. All of that is explained on the heroku docs: https://devcenter.heroku./articles/ssl-endpoint

Hope that helps.

I figured out and ssl requests working like a charm on my Centos6.9

  • install virtualmin on your server
  • setup Lets encrypt
  • Just refer

before your call to
var app = express();
or any other http(s) mechanism or app.listen(port),

  var options = {
    key: fs.readFileSync('/home/yourdomain/ssl.key'),
    cert: fs.readFileSync('/home/domain/ssl.cert'),
  };

Note: you must take in to account about 'No Access control allow origin'

本文标签: javascriptExpressjs netERRCONNECTIONCLOSEDStack Overflow