Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues on fresh debian 12 installation (ReferenceError: Cannot access 'app' before initialization and redirect loop) #22

Open
Esquirish opened this issue Apr 11, 2024 · 1 comment

Comments

@Esquirish
Copy link

Hello, I just cloned the repo in a fresh Debian 12 container with node v21.7.3.

upon running npm run start i got the following error:

> gptportal@1.0.0 start
> node server.js

/home/user/GPTPortal/server.js:12
app.use(bodyParser.json({ limit: '50mb' }));
^

ReferenceError: Cannot access 'app' before initialization
    at Object.<anonymous> (/home/giorgio/GPTPortal/server.js:12:1)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at node:internal/main/run_main_module:28:49

Which i solved by rearranging some lines in the server.js file:

// importing required node packages
require('dotenv').config();
const express = require('express');
const axios = require('axios');
const basicAuth = require('express-basic-auth');
const fs = require('fs');
const { marked } = require('marked');
const bodyParser = require('body-parser');
const app = express(); // Move this line up here
const download = require('image-downloader');
const cors = require('cors');
// Increase the limit for JSON bodies
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit: 50000 }));
app.use(express.json()); // for parsing application/json
app.use(express.static('public')); // Serves your static files from 'public' directory
app.use(cors());
const router = express.Router();
const { v4: uuidv4 } = require('uuid');

// openai
const OpenAI = require('openai').default;
// <other code remains the same>

However, when i try to access the application from the network: http://<local-server-ip>:3000/portal i get into a redirect loop to http://<local-server-ip>:3000/public/portal.html The page isn’t redirecting properly.

I'd appreciate some ideas on how to fix this, i'd love to try this app.

@Esquirish
Copy link
Author

I solved the redirect loop by commenting this in the server.js file:

app.get('*', (req, res) => {
  res.redirect('/public/portal.html');
});

Now i can access http://:3000/portal, but i get a CORS error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/message. (Reason: CORS request did not succeed). Status code: (null)". 

When running locally, it works without producing the above error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant