last day (15 days later) » 

03:55
This chat is about the question stackoverflow.com/q/56906758
Hi!
It's an honor for me to talk to you, I thank you so much.
Hello there
Excuse my ignorance, I swear I want to learn, but I still have doubts.
We all are learners here :)
Thank you. Did you understand my last question?
04:07
So does your website url contains the word public?
like http://xyz.com/public/?
no
I use heroku and when I upload my files to the repository, I upload a folder called "public"
If your website address is http://xyz.com/<nothing else here>, then your base-url is /.
then I do a redirect
Only /
in my files I have only /
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
04:11
Don't use the above code, it will not serve any JS/CSS files
const distDirectory = path.join(__dirname, 'dist');

app.get('*', function (req, res, next) {
const file_path = path.join(distDirectory, req.url.split('?').shift());
if (fs.existsSync(file_path)) next();
else res.sendFile(path.join(distDirectory, 'index.html'));
});

app.use(express.static(distDirectory));

app.listen(80, function () {
console.log('listening');
});
use your last code? right now I'm not in my office, so I can not prove, I just know that with your code I had not worked
this is my index.html
Can you provide me the link your your site, so I can see the error myself? if it is allowable.
I would, but I reversed the changes because my users should not have this error.
Can you provide me the full error message you received in your console?
It is not an error. simply the get requests, returns the index.html file
<base href="/"> is okay?
04:23
JS/CSS all returns index.html?
no, only my webservices
I'm trying to provide you with a link to the problem and the code you put here.
Are webservices hosted on the same domain?
<base href="/"> is okay?
I use mongoose and mongolab
with express
Yes base tag is OK
ok
04:25
So the same express is serving your angular app and webservices?
yes..
That is a conflicting scenario unless you handle it right
what can I do, I do not understand the problem.
So your problem is localhost/programa/detalle-programa/5cf7d27faa8e180017211754 should serve your web-service but you are receiving html response?
in localhost, everything works perfect. but in the heroku server, the web services return the index.html
04:28
Correct me if I am wrong
in localhost, everything works perfect. but in the heroku server, the web services return the index.html
And your routes working properly? JavaScript and CSS are loaded right?
yes..
on server?
yes
04:30
Ok I get it
look
Which express configuration are you using? the one I gave you?
webservices with post works good
but webservices with get return index.html
wait me please
const distDirectory = path.join(__dirname, 'public');

app.get('/*', function (req, res, next) {
const file_path = path.join(distDirectory, req.url.split('?').shift());
console.log(file_path)
if (fs.existsSync(file_path)) next();
else res.sendFile(path.join(distDirectory, 'index.html'));
});

app.use(express.static(distDirectory));
yes, your code
const express = require('express')
const bodyParser = require('body-parser')
const hbs = require('express-handlebars')
const html = require('html')
const app = express()
const api = require('./routes')
const path = require('path')
const cors = require('cors')
const fs = require('fs');
user are:
or not neccesary?
04:45
Where is webservice configuration?
In the same file?
yes
Your web-service configuration should be above angular configuration in the file, is it in that order?
If not you will only receive HTML files, no web-services
do you mean that I must first define the web services and then the part of the code that you put in?
right
angular configuration should be the last entries in it
I explain. I create different js to configure the webservices, I export it and in a folder called "routes" this is the configuration of the services web routes of the services, get, post, delete etc.
angular configuration is your code, right?
full code
'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const hbs = require('express-handlebars')
const html = require('html')
const app = express()
const api = require('./routes')
const path = require('path')
const cors = require('cors')
const fs = require('fs');
const router = express.Router();


app.use(cors());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
your code to the end of my code
right?
I love you man!
thanks!!
it worked
05:09
Great :)
Have a nice day :)
you have my bounty
:)

last day (15 days later) »