我有一个节点js应用程序,并将其部署到了Azure。
https://<mysite>.azurewebsites.net/orders
https://<mysite>.azurewebsites.net/item
这两个URL都应该有效,但只有第一个有效。如果我在本地主机上运行该应用程序,则它们都可以工作。给我的错误是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类:
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);
};