私のindex.jsファイルは次のようになります。最大の公共負荷に休憩のエンドポイントがノードサーバーで機能しないのはなぜですか?
var http = require('http');
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser')
var app = express();
var currentVideo = 'https://www.youtube.com/embed/9Q-ovNuireY';
// parse application/json
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(res) {
console.log("sup");
});
app.get('/currentVideo', function(req, res) {
res.send(200, {youtubeSrc: currentVideo});
});
http.createServer(app).listen(process.env.PORT ||3000, function() {
console.log('Example app listening on port 3000!');
});
私の静的なページと私のサーバーは罰金起動し、例のアプリのログを出力します。エンドポイントを取得しようとすると動作しませんが、私はhttp://localhost:{port}/currentVideoを打って、404を取得しました。
http:// localhost:{port}/currentVideo'は正しく{{port}が置き換えられましたか?どんなHTTPクライアントでテストしましたか? –
そうですが、ポートは動的ですがその右側です。そして私はブラウザでそれをテストしました。 – Grammin
@Grammin公開ページからAPIへのjavascript呼び出しをここに投稿してください。 –