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!