1

私は基本的に Azure で Web サイトを開始したばかりですが、何らかの理由で既に悪い要求エラーが発生しています。問題は、これが私の最初の Web サイトではなく、以前にこれに遭遇したことですが、今回は取得できません! 多分私はあまりにも疲れているか何か、誰かが私を助けることができますか? 次のファイルは、基本的に私が変更したすべてのものです。

サーバー.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'));
});

サムネイル.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' });
}; 

正直なところ、これが何であるかはわかりません。Microsoft の WebMatrix を IDE として使用しています。これは基本的に、Express Node.js テンプレートにすぎません。

更新:だから、この特定のエラーが発生しています:

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)
4

1 に答える 1

1

これを見た人に、私は自分の質問に答えました。はい、ヘキサシアニドの回答は役に立ちましたが、まだ悪いリクエストエラーが発生していたため、質問に対する回答ではありませんでした。私がしたことはこれでした。

私のindex.jsファイルはそのままです。routesフォルダーに新しい JavaScript ファイルを定義して名前を付けRoads.js、server.js ファイルに次のように入力しました。

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

これで、すべてのapp.get() コマンドRoads.###が 2 番目のパラメーターで使用されます。これは正しい解決策ではないかもしれませんが、機能し、以前にこの方法を使用して Web サイトを構築したことがあり、うまくいきました。

于 2013-08-26T19:11:43.010 に答える