[英]Cannot GET /file.js
在過去的幾天里,我一直在使用nodejs,但我一直試圖以某種方式運行它。 這就是我所做的:1.使用以下代碼創建file.js:
var express = require('express');
var app = express();
var path = require('path');
var Chance = require('chance');
var chance = new Chance();
app.get('/', function(req, res) {
if (chance.integer({min: 1, max: 10}) == 1) {
res.sendFile(path.join(__dirname + '/file1.js'));
} else {
res.sendFile(path.join(__dirname + '/file2.js'));
}
});
app.listen(80);
2.創建了file1和file2 javascripts(每個都包含一個window.alert。)3.使用如下配置啟動nginx:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://APP_PRIVATE_IP_ADDRESS:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
但是,每當我轉到ip / file.js時,它都會說:無法獲取/file.js
顯然我做了節點file.js並啟動了Nginx !!! 我為什么得到那個?
您不在ip/file.js
提供文件,而是在ip/
。 您的路線在這里定義:
app.get('/', function(req, res) { ... });
腳本的文件名與您從其訪問的地址無關。 為了獲得您期望的結果,路由定義必須看起來像這樣:
app.get('/file.js', function(req, res) { ... });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.