简体   繁体   English

带有Azure错误请求的Node.js Express

[英]Node.js Express with Azure Bad Request

I basically just started a website on Azure and I am already getting bad request errors for some unknown reason. 我基本上只是在Azure上启动了一个网站,由于某些未知原因,我已经收到了严重的请求错误。 The thing is this isn't my first website and I've encountered this before, but I just can't get it this time! 问题是这不是我的第一个网站,我以前也曾遇到过,但是这次我却无法获得它! Maybe I'm too tired or something, can somebody help me out? 也许我太累了或什么,有人可以帮我吗? The following files are basically all the things I've changed. 以下文件基本上是我已更改的所有内容。

server.js server.js

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var azure = require('azure');
var http = require('http');
var fs = require('fs');
var path = require('path');

var app = express();

var index = require('./routes/index');


app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

//Routing
app.get('/', index.splash);
app.get('/thumbnail', index.thumbnail);

//Utility
app.post('/file-upload', function(req, res) {
    // get the temporary location of the file
    var tmp_path = req.files.thumbnail.path;
    // set where the file should actually exists - in this case it is in the "images" directory
    var target_path = './public/images/' + req.files.thumbnail.name;
    // move the file from the temporary location to the intended location
    fs.rename(tmp_path, target_path, function(err) {
        if (err) throw err;
        // delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
        fs.unlink(tmp_path, function() {
            if (err) throw err;
            res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes');
        });
    });
});

//No Touch
http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

thumbnail.jade thumbnail.jade

h1= title
p Welcome to #{title}

form(method='post', enctype='multipart/form-data', action='/file-upload')
    input(type='file', name='thumbnail')
    input(type='submit')

index.js index.js

/*
 * GET home page.
 */

exports.index = function(req, res){
  res.render('Splash', {title: 'Express'});
};

exports.thumbnail = function (req, res) {
    res.render('thumbnail', { title: 'Express' });
}; 

I honestly have no idea what this could be I am using WebMatrix from Microsoft as my IDE and this is basically just their Express Node.js template. 老实说,我不知道我使用Microsoft的WebMatrix作为我的IDE是什么,这基本上只是他们的Express Node.js模板。

UPDATE: so I am getting this specific error: 更新:所以我得到这个特定的错误:

Application has thrown an uncaught exception and is terminated:
Error: .get() requires callback functions but got a [object Undefined]
    at Router.route.Route.sensitive (C:\Users\ShannonS\Documents\GitHub\CircuitsExpress\node_modules\express\lib\router\index.js:252:11)
    at Array.forEach (native)
    at Router.route (C:\Users\ShannonS\Documents\GitHub\CircuitsExpress\node_modules\express\lib\router\index.js:248:13)
    at Router.methods.forEach.Router.(anonymous function) [as get] (C:\Users\ShannonS\Documents\GitHub\CircuitsExpress\node_modules\express\lib\router\index.js:270:16)
    at Function.methods.forEach.app.(anonymous function) [as get] (C:\Users\ShannonS\Documents\GitHub\CircuitsExpress\node_modules\express\lib\application.js:412:26)
    at Object.<anonymous> (C:\Users\ShannonS\Documents\GitHub\CircuitsExpress\server.js:35:5)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

To anyone who sees this, I answered my own question. 对于任何看到这一点的人,我都回答了​​我自己的问题。 Yes hexacyanides answer did help but it was not the answer to the question as I was still getting bad request errors. 是的,六氰化物的答案确实有帮助,但这并不是问题的答案,因为我仍然遇到错误的请求错误。 What I did was this. 我所做的就是这个。

My index.js file is untouched. 我的index.js文件未更改。 I defined a new javascript file in the routes folder and then named it Roads.js and then in my server.js file, I just typed: 我在routes文件夹中定义了一个新的javascript文件,然后将其命名为Roads.js ,然后在我的server.js文件中输入:

var Roads =require('./routes/Roads');

now all of my app.get( ) commands use Roads.### in their second parameter. 现在我所有的app.get( )命令在其第二个参数中都使用Roads.### It may not be the right solution, but it works and I've built websites using this method before and they have turned out fine. 这可能不是正确的解决方案,但是它可以工作,而且我之前使用此方法构建过网站,但结果证明还不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM