Cadastrar
Login
Novo texto
Português
English
Português
Cadastrar
Login
Novo Texto
Importar Arquivo
Here is a more detailed explanation of what I was thinking about, and why I was talking about a "proxy". You mentioned using VueJS. Since the most common and easy way to develop a full featured Vue application is to use Vue Cli for scaffolding, and the Vue-Cli-Service dev server for hot reload, I thought it would be nice to use these, if you plan on having a maintainable codebase. By default, this dev server runs on `http://localhost:8080`. > Again, I'm only talking about the development phase. Now, here is how Neutralino works: it creates a local server, which hosts your app _(or a wrapper app, if you plan on hosting your UI on the web, but I'm disgressing)_, and provides a JS library called `neutralino.js` which you can use in your application to access OS functionality. All this library does is provide methods, which, internally, call an API on Neutralino's local server (same one which will serve your app). And it makes those XRH calls without specifying a host in the URL, so it has to be on the same host and port as your app. This can be on a random port if you leave it default, but let's say we configure it to be under port `9090` during development. Because we can't have 2 servers running on the same port. If we leave everything like this and use the `neutrino.js` in our app _(which is on port 8080 during dev)_, the library is going to try to access Neutralino's API on that same port. But it's not there. It's on port `9090`! ## Attempt #1 So I just thought "Hey, Vue CLI provides a nice ["proxy" option](https://cli.vuejs.org/config/#devserver-proxy)". It allows you to have requests redirected to another server when the route does not exist in the Vue app. So I set it up like this in `vue.config.js`: ```javascript module.exports = { devServer: { proxy: 'http://localhost:9090' } }; ``` Now, I can develop my Vue app as usual, and any call made by `neutralino.js` will be redirected to Neutralino's server. Perfect! Well... in theory. I noticed that GET requests would work (yay!), but POST requests would just stay pending. Humm, weird. So I digged a little in the Network tab, and saw that POST requests were using `x-www-form-url-encoded` format (which is normally in the shape of `key1=value1&key2=value2`). But instead, they're just sending plain JSON! So, already, this was fishy, they were using the wrong format for that kind of data. After a little more digging, I discovered that Vue's proxy was adding an `=` sign to that data, to make it valid before forwarding it (the JSON string was considered as a key with no value, making it `{"name":"USERNAME"}=`). So that made me realize Vue's proxy was not going to work, since you can't prevent it from adding an `=` sign. I discovered the same `=` sign was also added automatically when replaying the requests with Postman. That's a standard behavior. But Neutralino does not accept it. They made a poor job here by using a format which doesn't correspond to the plain JSON they're sending. ## Attempt #2 I made a second attempt, which I really did not want to do since it will make it harder to update Neutralino's version in the future: edit `neutralino.js` so that all the request URLs contained the actual port of Neutralino's server (`9090`). So now, my Vue app (`8080`) was making XHR requests directly to Neutralino's server (`9090`). But to no avail, the browser was blocking the requests because of CORS policy. ## Attempt #3 I then tried another experiment. I set up a third server (yeah, that's too much), which was a simple Express app, with the [express-http-proxy](https://www.npmjs.com/package/express-http-proxy) module. It ran on port `7070`, and was forwarding requests to port `9090` (Neutralino). I edited `neutralino.js` again, this time to make calls to port `7070`. So I was developping on port `8080`, making requests to Express on port `7070`, which forwarded them to Neutralino on port `9090`. It worked... but only for GET requests, again. That proxy was also adding `=` signs. ## Attempt #4 I thought of a 4th attempt, but that's when I decided to not spend any more time on this. I think this could work if I made my own proxy which would not add a `=`, but I had already wasted too much time. In the end, I really think it's Neutralino that needs to be fixed. I looked at their code, some parts were poorly made, and sadly it will take a lot of work to fix this. It's really sad, because this project seems to have the smallest footprint and still be able to handle Windows, Mac and Linux. Now you know why I was talking about a "proxy" :)
Configurações do Texto
Título do Texto :
[Opcional]
Guardar na Pasta :
[Opcional]
Selecionar
Syntax Highlighting :
[Opcional]
Selecionar
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiração do Texto :
[Opcional]
Nunca
Auto Destruir
10 Minutos
1 Hora
1 Dia
1 Semana
2 Semanas
1 Mês
6 Meses
1 Ano
Status do Texto :
[Opcional]
Público
Não Listado
Privado (somente membros)
Senha :
[Opcional]
Descrição:
[Opcional]
Tags:
[Opcional]
Criptografar Texto
(
?
)
Criar Novo Texto
No momento você não está logado, isso significa que você não pode editar ou excluir nada que você poste.
Cadastre-se
ou faça o
Login
Idiomas do site
×
English
Português
Você gosta de cookies?
🍪 Usamos cookies para garantir que você obtenha a melhor experiência em nosso site.
Saber mais
Concordo