totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

System routing #706

Closed DaisyMonte closed 5 years ago

DaisyMonte commented 5 years ago

Hi Peter, I have a route problem that I can't solve. In the development environment, my default route is empty. On the server, the default route is /behavioral.

In the development environment, all routes work. On the server, the system routing (404) do not work, but the others routes work.

I am using apache with reverse proxy. Can you help me?

default.js

const AssessmentController   = require('./avaliacao'); // Assessment
let Assessment = new AssessmentController(); // Assessment Instance

exports.install = function() {
    F.route('start/{type}', Assessment.canvas,         ['post','cors']); // Canvas
    F.route('assessment/{type}', Assessment.assessments, ['xhr', 'post'] ); // Assessments
    F.route('#404', Assessment.genericPage,  ['404']);
};

config

name : Behavioral Assessment
author : Daisy Machado
canvas_api : URL API Rest here
canvas_token : Token API Rest Here  
default-root : /behavioral

For now, I do not make GET calls, so I could do something like this:

exports.install = function() {
    F.route('start/{type}', Assessment.canvas, ['post','cors']); // Canvas
    F.route('assessment/{type}', Assessment.assessments, ['xhr', 'post'] ); // Assessments
    F.route('/*', Assessment.genericPage,  ['404']);
};

404 with error on my server:

image

404 running in the development environment:

image

Thank you!!!

petersirka commented 5 years ago

Hi @DaisyMonte, can you send me your source code to my email address? It's a bit complicated for me because I need to see your entire code. But:

This is a clearer code:

exports.install = function() {

     // Routes
     ROUTE('POST /start/{type}/',      Assessment.canvas);               // Canvas
     ROUTE('POST /assessment/{type}/', Assessment.assessments, ['xhr']); // Assessments
     ROUTE('GET  /*',                  Assessment.genericPage);

     // Enables CORS for all routes
     CORS();
};

Thank you!

DaisyMonte commented 5 years ago

Hi Peter!

I followed your instructions, but the CORS() statement did not work with the version of the framework I was using in the project (2.9.1). It's an old project, so I upgraded TotalJS, reinstalled the packages with npm, made the necessary adjustments and it worked perfectly! Thank you very much!

default

const AssessmentController  = require('./assessment');                  // AssessmentController
let Assessment              = new AssessmentController();               // Instance AssessmentController

exports.install = function() {
    ROUTE('POST start/{type}',      Assessment.canvas);                 // Canvas
    ROUTE('POST assessment/{type}',  Assessment.assessments, ['xhr']);   // Assessments (/abas or /cards)
    ROUTE('#404',                   Assessment.genericPage);            // System routing - 404  
    CORS();
};

config

name : Behavioral Assessment
author : Daisy Machado
canvas_api : URL API Rest here
canvas_token : Token API Rest Here  
default_root : /behavioral