1

I'm really struggling trying to understand what's going on here. I'm trying to create a tracker in order to see what pages my visitors navigates more frequently;

Before starting :

  • BE : Node.js and Express
  • FE : VUE.js with axios in order to perform callouts.
  • '{baseUrl}' : is a placeholder that on building time is replaced with a specific url, ie. localhost

I'm able to perform the callout to the BE and write everything with a custom logger all the infoes I want into a file but for some reason i keep getting :

xhr.js:160 POST url/loggerMe 404 (Not Found)
createError.js:16 Uncaught (in promise) Error: Request failed with status code 404

The general Idea : Before each routing (within VUE.Js) perform a callout to te BE to "url"/loggerMe and save the needed info into a file-db-somewhere

Here it goes my implementation :

index.js Vue

import Vue from 'vue'
import axios from 'axios'

Vue.use(Router)
const rout = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [{
        ...
    }]
})
rout.beforeEach((to, from, next) => {
    try {
        axios.post('{baseUrl}' + '/loggerMe', {})
        next()
    } catch (error) {
        ...
    }
})

server.js Node.js - Express

const logger = require('./controllers/logger')

const app = express()
app.route('/loggerMe')
    .post(logger.logNow)

logger.js

exports.logNow = async function(req, res, next) {
    let today = new Date()
   let jsonLog = JSON.stringify({});
   await this.jsonLogToFile(navDirectory, today, jsonLog)

    next()
}

Thank you so much for your help!

calibro22
  • 26
  • 5
  • May seem a silly question, but you do know what a 404 error means? – Jaromanda X Sep 24 '20 at 05:36
  • that he doesn't find the requested resource. The thing that bothers me is that, eventhought I get this error, everything "seems to work as expected". – calibro22 Sep 24 '20 at 05:39
  • Can you verify that you're running the Express server on one port (i.e. 3000) and the Vue.js app on another (i.e. 8080)? I would expect them listening on different ports, and I'd expect that baseUrl variable in your axios post call to include the Express server's port. – Mike Wright Sep 24 '20 at 05:48
  • yep! the Express server is running on port 3000 and the baseUrl is something like localhost:3000. Regarding the Vue.js app, i guess is running on port 80 cause I'm running everything on a server after building the project – calibro22 Sep 24 '20 at 06:47
  • I don't understand how you construct your url ... what is `'{baseUrl}'` ?? – Sélim Achour Sep 24 '20 at 07:54
  • your are right! that might something i should add in the description.. since we have 4 different environments (dev, sys, uat, prod) in order to not manually change the url that has to be referenced by all the callout that are made in the project, I created this placeholder that, on building time (npm run build), is replaced with the right url to call. – calibro22 Sep 24 '20 at 09:17

0 Answers0