Некоторые URL-адреса развернутого приложения работают, а другие нет - PullRequest
0 голосов
/ 02 января 2019

У меня есть приложение js для узла, и я развернул его в Azure.

https://<mysite>.azurewebsites.net/orders https://<mysite>.azurewebsites.net/item

Оба эти URL-адреса должны работать, но работает только первый.Если я запускаю приложение в localhost, они оба работают.Ошибка, которая дает мне это 404 и говорит:

the resource you are looking for has been removed, had its name is temporarily unavailable

Это класс itemRoute.js:

const express = require('express');
const router = express.Router();

const item_controller = require('../controllers/itemController');

router.get('/',item_controller.getAll);
router.get('/:id',item_controller.getById);
router.get('/:id',item_controller.getByIdParts);
router.get('/name/:name', item_controller.getByName);
router.post('/',item_controller.post);
router.put('/:id',item_controller.put);
router.delete('/:id', item_controller.deleteItem);
module.exports = router;

, и это orderRoute.js:

const express = require('express');
const router = express.Router();

const order_controller = require('../controllers/orderController');

router.get('/test', order_controller.test);

router.post('/',order_controller.post);
router.get('/', order_controller.getAll);
router.get('/:id',order_controller.getById);
router.get('/user/:userEmail', order_controller.getByUser);
router.get('/city/:city', order_controller.getByCity);
router.get('/:id/:reference', order_controller.getByReference);
router.get('/item/:itemId', order_controller.getByItem);
router.get('/state/:state', order_controller.getByState);
router.get('/:id/item', order_controller.getItem);
router.delete('/:id', order_controller.deleteOrder);
module.exports = router;

класс app.js (переменная dev_db_url с ***, потому что у него был пароль):

//app.js
const express = require('express');
const bodyParser = require('body-parser');

const order = require('./app/routes/orderRoute'); //Imports routes for the encomendas
const item = require('./app/routes/itemRoute');

const app = express();

// Set up mongoose connection
const mongoose = require('mongoose'); //.set('debug',true);
let dev_db_url = 'mongodb:***;
const mongoDB = process.env.MONGODB_URI || dev_db_url;
mongoose.connect(mongoDB, { useNewUrlParser: true });
mongoose.Promise = global.Promise;
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));


app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));//false})); //problem w/ objects from armarioswebapi was here, changed to true



app.use('/orders', order);
app.use('/item', item);


//Added CORS (Cross-Origin Resource Sharing) support 
var cors = require('cors');
// app.use(cors());
app.use(cors({
    origin: true,
    credentials: true
}));

// Node is complaining because the TLS (SSL) certificate it's been given is self-signed (i.e. it has no parent - a depth of 0). It expects to find a certificate signed by another certificate that is installed in your OS as a trusted root.

// Your "fix" is to disable Node from rejecting self-signed certificates by allowing ANY unauthorised certificate.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";


let port = process.env.PORT || 1234;

//app.listen(port, () => {
app.listen(process.env.PORT || 1234, () => {
    console.log('Orders server is up and running on port number ' + port);
});

itemController class:

const service = require('../services/itemService');

exports.test = function (req, res) {
    res.send('Greetings from the Test controller!');
};
exports.post = function (req, res) {
    service.post(req,res);

};

exports.getById = function (req, res) { 
    service.getById(req, res);

};

exports.getByIdParts = function (req, res) { 
    service.getByIdParts(req, res);

};

exports.getByName = function (req, res) { 
    service.getByName(req, res);

};

exports.getAll = function (req, res) { 
    service.getAll(req, res);

};

exports.allItems = function (req, res) { 
    service.getItems(req, res);

};

exports.put = function (req, res) {
    service.put(req, res);

};

exports.deleteItem = function (req, res) {
    service.deleteItem(req, res);

};
...