Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[nextjs] External URL is being blocked by CORS policy #2003

Closed
5ervant opened this issue Apr 26, 2020 · 5 comments
Closed

[nextjs] External URL is being blocked by CORS policy #2003

5ervant opened this issue Apr 26, 2020 · 5 comments
Labels

Comments

@5ervant
Copy link

5ervant commented Apr 26, 2020

Referring to my react-three-fiber "useLoader external URL is being blocked by CORS policy" issue.

Is there a way to configure Next.js server's CORS policy?
If any, where's the guideline?

Because whenever I load external files on my react-three-fiber scene, I'm getting this console error:

Access to XMLHttpRequest at 'https://github.com/zeit/next.js/blob/canary/examples/with-three-js/public/glb/stork.glb' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here's my "server.js":

const { startServerAsync } = require('@expo/next-adapter');

startServerAsync(__dirname, {
  port: 3001,
});

This is definitely important functionality for a Next.js application.
I hope there's already a fix for this.

Reference


I already tried this "server.js" code:

const { createServerAsync } = require('@expo/next-adapter');
const Cors = require('cors');

const projectRoot = __dirname;

createServerAsync(projectRoot, Cors()).then(({ server, app }) => {
  const port = 3000;

  server.listen(port, () => {
    console.log(`> Ready on http://localhost:${port}`);
  });
});

But getting this terminal error:

C:\Users\USER\Documents\PROJECTS\PLATFORM\APP_NAME\node_modules\cors\lib\index.js:219
            originCallback(req.headers.origin, function (err2, origin) {
                               ^

TypeError: Cannot read property 'headers' of undefined
@5ervant
Copy link
Author

5ervant commented Apr 27, 2020

@EvanBacon May I know if there's an example how to load a .GLB file with expo-three?

@EvanBacon
Copy link
Contributor

In React Native you can load different asset types like this https://github.com/expo/expo-three#expothreeloadasync
I'm unsure how to do the same in Next.js.

@EvanBacon EvanBacon added bug with another tool Platform: web Using Expo in the browser labels Apr 28, 2020
@5ervant
Copy link
Author

5ervant commented Apr 28, 2020

BUG: By the way, app: (App) => App is throwing an UnhandledPromiseRejectionWarning: TypeError: app.getRequestHandler is not a function.

const { createServerAsync } = require('@expo/next-adapter');
const cors = require('cors');

createServerAsync((projectRoot = __dirname), {
  // UnhandledPromiseRejectionWarning: TypeError: app.getRequestHandler is not a function
  app: (App) => {
    App.use(cors()); // To enable all CORS requests
    return App;
  },
}).then(({ server, app }) => {
  // ...
});

I'll end up and try using react-native-webview to support multi-platform Three.js graphics.

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Apr 12, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

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

No branches or pull requests

2 participants