neutralinojs / neutralino.js

JavaScript API for Neutralinojs

Home Page:https://neutralino.js.org/docs/api/overview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Not found" on dynamic routes

ExQDev opened this issue · comments

I'm trying to make OAuth in my app, using Neutralino, Vite and Vue, but on any routes, that are not same with 'http://localhost:8080/dist' it returns 404.

I cannot even use parameters in this base route, cannot use root (http:/localhost:8080) as main url, thus it breaks Vue with relative paths.

So, if there is any way to make normal SPA with Neutralino, how can I do this?
I want to handle routes with vue-router at least, and be able to use parameters in URL.

Sorry, not neutralino problem

No, still get 404 when trying to get page with address like 'http://localhost:8080/oauth?code=...'
It applies just fixed initial routes.

Solution: make mini server with extensions and send events to main app when redirected to localhost.

My sample:

const argv = require('minimist')(process.argv.slice(2));
const WS = require('websocket').w3cwebsocket;
const { v4: uuidv4 } = require('uuid');
const express = require('express')

const app = express()
const port = 3333

const NL_PORT = argv['nl-port'];
const NL_TOKEN = argv['nl-token'];
const NL_EXTID = argv['nl-extension-id'];

let client = new WS(`ws://localhost:${NL_PORT}?extensionId=${NL_EXTID}`);

app.get('/oauth', (req, res) => {
  client.send(JSON.stringify({
    id: uuidv4(),
    method: 'app.broadcast',
    accessToken: NL_TOKEN,
    data: {
        event: 'callback',
        data: {
          // yours data
        }
    }
  }));
  res.send('Success, you can close this window now')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

client.onerror = function () {
    console.log('Connection error!');
};

client.onopen = function () {
    console.log('Connected');
};

client.onclose = function () {
    console.log('Connection closed');
    // Make sure to exit the extension process when WS extension is closed (when Neutralino app exits)
    process.exit();
};