2013-08-24 7 views
1

기본적으로 방금 Azure에서 웹 사이트를 시작했으며 일부 알 수없는 이유로 잘못된 요청 오류가 발생했습니다. 것은 이것이 나의 첫번째 웹 사이트가 아니고 전에 이것과 마주 쳤지 만, 나는 단지 이번에 그것을 얻을 수 없다! 어쩌면 너무 피곤하거나 어쩌면 누군가 나를 도울 수 있습니까? 다음 파일은 기본적으로 내가 변경 한 모든 것입니다.Azure Bad Request가있는 Node.js Express

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

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

/* 
* GET home page. 
*/ 

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

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

솔직히이 이게 뭔지는 모르겠다. 내 IDE로 Microsoft의 WebMatrix를 사용하고 있는데, 이는 기본적으로 Express Node.js 템플릿입니다.

UPDATE : 그래서 난이 특정 오류가 발생하고이를보고, 나는 내 자신의 질문에 대답 사람에게

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) 

답변

1

. 예 hexacyanides 대답은 도움을 주었지만 잘못된 요청 오류가 계속 발생하면서 질문에 대한 답변이 아닙니다. 내가 한 일은이 일이었다.

index.js 파일은 변경되지 않았습니다. 나는 Roads.js라는 다음 내 server.js 파일에, 나는 방금 입력 한 후 경로에 새로운 자바 스크립트 파일 폴더를 정의 : 내 app.get() 명령의 현재

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

모두에서 Roads.###을 사용하여 자신의 두 번째 매개 변수. 맞은 해결책일지도 모르지만, 그것은 작동하고 나는이 방법을 사용하여 웹 사이트를 전에 건설하고 벌벌로 판명했다.