Saturday 18 August 2018

Running NodeJS on cPanel (Htaccess problem)

Hello!I have installed NodeJS onto my cPanel account, then I uploaded my NodeJS website/app onto my public_html/website then I added the following code to my htaccess:RewriteEngine On RewriteRule ^$ http://localhost:51521/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^$ http://localhost:51521/$1 [P,L] After adding that code to .htaccess, I ran the NodeJS application, and the website ran, and the homepage looked fine and all there, but when I go to any other pages, like for an example go to the About me page, It shows Not Found The requested URL /about was not found on this server. 404 not found pictureThen I proceeded to make a slight change in the .htaccess:"^$" to "^(.*)$" in the last lineRewriteEngine On RewriteRule ^$ http://localhost:51521/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ http://localhost:51521/$1 [P,L] This caused the website to through an error showing: "404: index.php" and the homepage loaded but was missing a lot of stuff, BUT! the other pages showed but not fully there.. here is an image of the homepage: homepage after tweak and here's a picture of the second page that was showing 404 before the tweaking: second pageI have been researching non stop and I still can't find the solution, but here is my nodejs execution code:var createError = require('http-errors'); var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); var mongoose =require('mongoose'); var methodOverride = require('method-override'); var nodemailer = require('nodemailer'); // mongoose.connect('mongodb://jehad:jhadayman1@ds121268.mlab.com:21268/hoca'); mongoose.connect('mongodb://jhad96:jhad96@ds121268.mlab.com:21268/hoca'); mongoose.Promise = global.Promise; var indexRouter = require('./routes/index'); var usersRouter = require('./routes/users'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(methodOverride("_method")); app.use(express.static(path.join(__dirname, 'public'))); app.use('/uploads',express.static(path.join(__dirname, 'uploads'))); app.use('/', indexRouter); app.use('/users', usersRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { next(createError(404)); }); Here is a picture of the nodejs website files: filesI really appreciate your help guys :) much love

Submitted August 18, 2018 at 10:42AM by defiledx1

No comments:

Post a Comment