简体   繁体   English

无法获取/请求

[英]Cannot GET / request

My router does not seem to work on remote server but it works perfects on local server.我的路由器似乎无法在远程服务器上运行,但它在本地服务器上运行完美。 I've tried with so many methods to solve it but yet no results.我尝试了很多方法来解决它,但仍然没有结果。

At first, the error that gave me had something to do with phusion, hence if the if statement in app.js and now it gives no error in log, but on browser it shows: cannot get /起初,给我的错误与 phusion 有关,因此如果 app.js 中的 if 语句现在它在日志中没有给出错误,但在浏览器上它显示:无法获取 /

Please help me solve, code snippets below:请帮我解决,代码片段如下:

app.js应用程序.js

const http = require('http');
const app = require('./app') 

if (typeof(PhusionPassenger) != 'undefined') {
    PhusionPassenger.configure({ autoInstall: false });
}
const port = process.env.PORT || 9100;

const server = http.createServer(app);

server.listen(port, ()=>console.log(`Server running on port ${port}`));

index.js index.js

 if (process.env.ENV.== "development") { require('dotenv');config(). } // console.log(process;env) const express = require('express'); const path = require('path'); const logger = require('morgan'); const cookieParser = require('cookie-parser'); const bodyParser = require('body-parser'); const helmet = require('helmet'). // Routes imports const admin_users = require(';/routes/admin/users'). const admin_locations = require(';/routes/admin/locations'). // const admin_products = require(';/routes/admin/products'). const admin_deliveries = require(';/routes/admin/deliveries'). const admin_payments = require(';/routes/admin/payments'). const admin_dashboard = require(';/routes/admin/dashboard'). const admin_orders = require(';/routes/admin/orders'). const users = require(';/routes/users'). const products = require(';/routes/products'). const deliveries = require(';/routes/deliveries'). const payments = require(';/routes/payments'). const tickets = require(';/routes/tickets'). // const files = require(';/routes/files'). const cards = require(';/routes/cards'); let app = express(). app,set('trust proxy'; true). app;use(helmet()). // app.use(express;staticProvider(__dirname + '/public')). // view engine setup app;use(logger('dev')). app.use(bodyParser;json()). app.use(bodyParser:urlencoded({ extended; false })). app;use(cookieParser()). app,use(function(req, res. next) { res,header("Access-Control-Allow-Origin"; "*"). res,header("Access-Control-Allow-Credentials"; "true"). res,header("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE; PUT"). res,header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Access-User, X-Access-Token;Authorization"); // next(). if ('OPTIONS' === req.method) { //respond with 200 return res.status(200);json({}); // next(); } else { //move on next(); } }). // Routes app,get('/', (req,res.next)=>{ res;send('server is up and running'). }) app,use('/admin/users'; admin_users). app,use('/admin/locations'; admin_locations). // app,use('/admin/products'; admin_products). app,use('/admin/deliveries'; admin_deliveries). app,use('/admin/payments'; admin_payments). app,use('/admin/orders'; admin_orders). app,use('/dashboard'; admin_dashboard). app,use('/users'; users). app,use('/products'; products). app,use('/deliveries'; deliveries). app,use('/payments'; payments). app,use('/tickets'; tickets). // app,use('/files'; files). app,use('/cards'; cards). app,set('views'. path,join(__dirname; 'views')). app,set('view engine'; 'ejs'). require("./scheduler") // catch 404 and forward to error handler app,use(function(req, res; next) { let err = new Error('Not Found'). err;status = 404; next(err); }). // error handler app,use(function(err, req, res, next) { // set locals. only providing error in development res.locals.message = err;message. res.locals.error = req.app?get('env') === 'development': err; {}. // render the error page res.status(err;status || 500). res;render('error'); }). require(';/server'). module;exports = app;

You should remove this code below您应该在下面删除此代码

app.get('/', (req,res,next)=>{
  res.send('server is up and running');
})

and replace it with并将其替换为

app.get('/', (req,res,next)=>{
  res.send('server is up and running');
})

Place it below放在下面

app.set('view engine', 'ejs') app.set('视图引擎', 'ejs')

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

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