If I navigate to http://myurl.com/test
I get back on the page Reached me!
as I should. However, when I navigate to https://myurl.com/test
, chrome says Error: Cannot match any routes. URL Segment: 'test'
. All my api/user
routes work perfectly on either http or https.
NOTE: When I remove the two app.use lines for Angular, /test then works on both http and https, but obviously my Angular project is then gone :/
server.js
const { mongoose } = require('./database/db');
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
var userController = require('./controllers/userController');
app.use(cors({ origin: '*' }));
const port = process.env.PORT || 3000;
server.listen(port, () => console.log('Server started at port : ' + port));
app.use(bodyParser.json());
app.use('/api/user', userController);
// here lies the client stuff!
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'clientWrapper'));
app.get('/test', (req, res)=>{
res.send('Reached me!');
})
// This stuff has to be after the app.get stuff or it will override it!
// DOesn't work without this
app.use('/', express.static(path.join(__dirname, 'angular')));
// doesn't let you go straight to URLS without this!
app.use((req, res, next) => {
res.sendFile(path.join(__dirname, 'angular', 'index.html'));
});