Commit Graph

107 Commits

Author SHA1 Message Date
Lorenzo Blasa
ce9feae44f Attach handlers for process errors
Summary:
^
This is an effort to capture and log these errors as to gain visibility when failures occur.

Reviewed By: passy

Differential Revision: D37412861

fbshipit-source-id: 09687a31797aac4c377aa98944ab0701bdf45466
2022-06-24 07:56:42 -07:00
Lorenzo Blasa
335dec1a08 Adds some settings to check flipper-server state
Summary:
There's one setting: to enable or disable flipper-server.

However, I've added some current running state to it. If there's a better way of doing this, please do let me know.

Reviewed By: aigoncharov

Differential Revision: D37276670

fbshipit-source-id: f6c941cf0cfe55c267b9bcb9f799934fba1e28ef
2022-06-22 05:26:11 -07:00
Lorenzo Blasa
8c67b049ab Attach connection handler earlier
Summary:
This change attaches our event handlers as soon as the ws is created.

As a consequence, we need to wait until the server has created any necessary instances required to process incoming requests.

To achieve this, I created a type called `Lazy`.

This type wraps around a value and a promise to that value. Callers can check if the value is set. If not, callers can wait for it.

Ultimately, the value can be set outside of the promise itself.

Reviewed By: passy

Differential Revision: D37284939

fbshipit-source-id: 17dec548d7155a3d65440c9584cec07cbb826c37
2022-06-21 12:48:43 -07:00
Lorenzo Blasa
9cc8e4076f flipper-server refactor
Summary:
This changes moves most of the functionality found in flipper-server to flipper-server-core.

flipper-server will mostly be a package that wraps around flipper-server-core. Staying in flipper-server:
- Command line args
- Orchestration to start the necessary servers

Reviewed By: aigoncharov

Differential Revision: D36807087

fbshipit-source-id: f29002c7cc5d08b8c5184fdaaa02ba22562a9f45
2022-06-07 02:42:16 -07:00
Lorenzo Blasa
ee64216725 Extract logger and write to file
Summary:
This change extracts logging logic out from startFlipperServer.

Logs will also be written to disk.

Reviewed By: passy

Differential Revision: D36473768

fbshipit-source-id: b1df9df79b4aced0d3ba2e8c243aa8d44cf83703
2022-06-01 02:37:03 -07:00
Lorenzo Blasa
2fe7e73175 Refactor checks to see if socket is in use
Summary:
These are utility methods that are not specific to startServer.

They will be reused by other components needing to check if something is listening to a port.

Make socket path is also extracted.

Reviewed By: passy

Differential Revision: D36473641

fbshipit-source-id: 73ed67912052896696b59670cb757d22761eeaa1
2022-05-31 03:31:05 -07:00
Andrey Goncharov
4eca8d1088 Add isHeadlessBuild to EnvironmentInfo
Summary: Allows to attribute errors to flipper server or flipper electron

Reviewed By: passy

Differential Revision: D36698504

fbshipit-source-id: 6d07216fd05aa48b7c8cca5b53145916b64526eb
2022-05-27 02:37:53 -07:00
Andrey Goncharov
17b2e9d375 Connect companion events to Flipper Server
Reviewed By: passy

Differential Revision: D36517762

fbshipit-source-id: c6318b1b0705d1e6cbcf73973e2d6c9196914491
2022-05-23 03:38:23 -07:00
Lorenzo Blasa
aca1aca29c Accept connections from localhost coming from port 3000
Summary:
^

flipper-server verifies the origin of incoming connections as a way of preventing any host from connecting to flipper.

That's good.

This change expand the list of allowed origins to include localhost:3000 which is the default origin for Electron apps.

Error without this change:
```
Refused socket connection from cross domain request, origin: http://localhost:3000, host: localhost:52342. Expected origins: http://localhost:52342 or http://[::1]:52342 or http://::1:52342. Expected hosts: localhost:52342 or [::1]:52342 or ::1:52342
```

Reviewed By: passy

Differential Revision: D36440363

fbshipit-source-id: 883cadb49f245bca5d0a53a4f58c08cf45dd0189
2022-05-17 04:20:30 -07:00
Andrey Goncharov
d1ed676a48 Remove dynamic dependencies from flipper-server
Summary:
Currently, Flipper Server has a few productions dependencies (mac-ca, node-fetch) that are not bundled with the Flipper Server. It makes it harder to distribute Flipper Server, as now all potential consumers need not only to download the bundle, but also install these additional dependencies.
This diff makes it possible to bundle `mac-ca` and `node-fetch` with Flipper Server. As a result, Flipper Server becomes dependency-free in production.

Reviewed By: lblasa

Differential Revision: D36345213

fbshipit-source-id: 2cd6ba1b3301b45dc2295891964ba020fd107586
2022-05-13 03:19:47 -07:00
Lorenzo Blasa
242d26e199 Rename and documentation for start dev server (attach)
Summary:
Same as with the previous diff.

The function doesn't really start a server. Instead it attaches the routing of messages from the existing server into FlipperServer.

Reviewed By: passy

Differential Revision: D36310703

fbshipit-source-id: 7ac9a742fb36c3806597382c9aadcf96f4770484
2022-05-11 06:56:20 -07:00
Lorenzo Blasa
582966d139 Attach instead of start dev server and documentation updates
Summary:
^

Instead of 'start' use 'attach' as it seems closer to what the function actually does.

Reviewed By: passy

Differential Revision: D36310846

fbshipit-source-id: db90efc6ec3207b1a5a38139a3ba01d2f7d2aebd
2022-05-11 06:56:20 -07:00
Lorenzo Blasa
453ec4bd83 Rename base server to just server
Summary:
^

BaseServer doesn't really have any meaning. So, change it to just Server as it really creates the Express app and HTTP server attached to it.

Reviewed By: passy

Differential Revision: D36310822

fbshipit-source-id: eee5a2a395ca726679c1c4756ed58d4bc6be3cb8
2022-05-11 06:56:20 -07:00
Lorenzo Blasa
2493de75ab Remove unused import
Summary: ^

Reviewed By: passy

Differential Revision: D36310809

fbshipit-source-id: c9faa2b685fc57c8a022cf497a843f3c137716d7
2022-05-11 06:56:20 -07:00
Lorenzo Blasa
1818b87166 Rename startWebServerDev to startDevServer
Summary:
Rename 'startWebServerDev' to just 'startDevServer'.

It isn't really starting a web server though, more like installing routings and middleware to the existing created server.

Reviewed By: passy

Differential Revision: D36310765

fbshipit-source-id: 0af772012525fd7ad19e2aa6fa73cb3e7dcf2bef
2022-05-11 06:56:20 -07:00
Lorenzo Blasa
ec667bc26d Log listening port
Summary: Slight changes to the URL and port logging.

Reviewed By: passy

Differential Revision: D36310796

fbshipit-source-id: 553b9ce932792c471f8e0e2c1a0c7d79897ad59d
2022-05-11 06:56:20 -07:00
Pascal Hartig
14b83ad050 Don't tear down server on disconnect
Summary: These safeguards were added based on a discussion in D35088208 (56e94394ca) but turned out to be counter-productive. Every time a client disconnects now, we're tearing down the socket and the server, allowing for no future connections.

Reviewed By: lblasa

Differential Revision: D36252605

fbshipit-source-id: c3b6f85dea4054505a47d24a72a4aac403371c0f
2022-05-10 08:45:57 -07:00
Andrey Goncharov
b4498f070f Add flipper-server-companion to flipper-server
Summary: Start flipper-server-companion whenever a client connects to flipper-server and sets `server_companion` query parameter in a connection URL to true

Reviewed By: mweststrate

Differential Revision: D36098169

fbshipit-source-id: eb953e7d680b30aef1340f059264112387264c05
2022-05-10 05:13:24 -07:00
Andrey Goncharov
98dde53cda Add companion logging
Summary: Add top-level error logging to flipper-server. Use the top-level logging mechanism in flipper-companion.

Reviewed By: lblasa

Differential Revision: D36252218

fbshipit-source-id: 58d22b3b9bd51e597b5250478640f54d10277861
2022-05-10 05:13:24 -07:00
Pascal Hartig
3032736294 Fix type errors for flipper-server and flipper-ui-browser
Summary:
Before:

```
flipper-server/src/startBaseServer.tsx(222,30): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.
flipper-ui-browser/src/flipperServerConnection.tsx(25,9): error TS2322: Type 'Timeout' is not assignable to type 'number'.
```

Reviewed By: nikoant

Differential Revision: D36100188

fbshipit-source-id: 1913a43109a0e068394a188d362f6a9e473e7904
2022-05-03 09:55:04 -07:00
Pascal Hartig
fd23a9d626 Clean up socket on exit
Summary: Be more aggressive in cleaning up after ourselves. Using a tiny library by Sindre that handles standard exit events, SIGTERM and SIGINT.

Reviewed By: aigoncharov

Differential Revision: D35281772

fbshipit-source-id: a789f90f172b3aa3e187739cf2b7fefa75405891
2022-03-31 08:57:13 -07:00
Pascal Hartig
cfcbc75de9 Take unix domain socket max length into account
Summary: lawrencelomax helpfully pointed out that there's a legacy limit for the path length of unix domain sockets. Checking here and falling back to `/tmp` in case we're going over. This could have caused some gnarly support issues, so I'm glad we caught this before it went live.

Reviewed By: aigoncharov

Differential Revision: D35257794

fbshipit-source-id: 68a7b62d6d6863efa4b3ce84d7735b1c1a45a174
2022-03-31 06:29:21 -07:00
Pascal Hartig
5ce82405f7 Socket proxying error handling
Summary: More careful error handling as discussed in D35088208.

Reviewed By: aigoncharov

Differential Revision: D35251661

fbshipit-source-id: 8baab2b454494846411f7084e29c5fa668bc2f31
2022-03-31 06:29:21 -07:00
Pascal Hartig
3d3e53c9e0 More careful socket cleanup
Summary: Instead of just deleting, we first check if it's already in use. The behaviour in case it *is* in use, is not great but mirrors what happens when the port is occupied.

Reviewed By: aigoncharov

Differential Revision: D35188965

fbshipit-source-id: 9bb5a7a9bacec6987ea72bbd084e40d5b30f9796
2022-03-31 06:29:21 -07:00
Pascal Hartig
56e94394ca Serve on domain socket
Summary: Open a domain socket by default and proxy all browser requests via TCP to it. That allows us to connect to a running server regardless of its local port.

Reviewed By: aigoncharov

Differential Revision: D35088208

fbshipit-source-id: d167852162e63f68c804c379b4421f5cc0d33df2
2022-03-31 06:29:21 -07:00
Pascal Hartig
c662f3679d /health endpoint
Summary: Add a simple endpoint to the server to check if it's up and running.

Reviewed By: aigoncharov

Differential Revision: D35087344

fbshipit-source-id: ec490fdb11042e7a7e4b9b944b018c4c9853ed49
2022-03-25 07:59:42 -07:00
Pascal Hartig
d40ff61870 Recover from args argument being uniterable
Summary:
Another kind of error that can easily be triggered during testing that will kill the server otherwise.

Changelog: Make it possible to recover from malformed JSON in server requests

Reviewed By: timur-valiev

Differential Revision: D34932896

fbshipit-source-id: 7c6acfd53ffbd85a54a786d74c99bcccb64d85cb
2022-03-16 16:39:23 -07:00
Pascal Hartig
9c5d1a32c5 Recover from malformed JSON
Summary: Following up on D34787674 (f85def32fb).

Reviewed By: aigoncharov

Differential Revision: D34930249

fbshipit-source-id: f209a638c1281957fd2b03b6fc50389bd98bc5f6
2022-03-16 16:39:23 -07:00
Andrey Goncharov
f85def32fb Migrate from socket.io
Reviewed By: passy

Differential Revision: D34787674

fbshipit-source-id: 63d7c166ea29d14c96f0646a045e3f6fa93472e2
2022-03-10 10:31:24 -08:00
Pascal Hartig
35428ca039 Keytar platform/arch
Summary:
There appears to be an issue with login on M1 Macs right now. To address this, this resolves the native binary based on a `(platform, arch)` tuple.

The binaries are from here: https://github.com/atom/node-keytar/releases/tag/v7.9.0

The binary size increase here is notable so as a follow-up we could remove the non-relevant binaries as part of the packing process.

Reviewed By: aigoncharov

Differential Revision: D34685236

fbshipit-source-id: d860a59517a769a59055dfca24d01baecd8d1430
2022-03-08 12:19:52 -08:00
Andres Orozco Gonzalez
5b6000b424 add localhost specification for IPV6 without square brackets
Summary: Socket.io-client sends the host as ::1 instead of [::1] when using IPV6 to communicate with Flipper, that is the reason the communication was always being refused.

Reviewed By: mweststrate

Differential Revision: D34679825

fbshipit-source-id: b7431ad23f743276c11619d7cdb5c83594dee43a
2022-03-07 02:40:11 -08:00
Andres Orozco Gonzalez
5b5ce92519 Add support to binding both IPv6 and IPv4 ports
Summary: Add support for binding the same port in flipper in both the IPv6 and IPv4 interfaces

Reviewed By: mweststrate

Differential Revision: D34591022

fbshipit-source-id: e28239c24425885ee442d93b84bb38902d521a0c
2022-03-03 00:31:08 -08:00
Andres Orozco Gonzalez
b2dae4da81 Add support to load settings from options (flag) and default to specific options
Summary: This change gives priority to a user option settingsString to set up the flipper-server configuration and load them from a json string. Also giving the user the chance to avoid flipper-server looking at the launcher config files in the computer

Reviewed By: mweststrate

Differential Revision: D34210110

fbshipit-source-id: 9e852b79da106b5140c59116fd7d0c0f3155e620
2022-02-16 06:23:45 -08:00
Michel Weststrate
ebc4752077 Left some code comments
Summary: Added some additional code comments as requested in earlier diffs

Reviewed By: passy

Differential Revision: D33361691

fbshipit-source-id: 2d1adc8830af58e6cb7bac4b283a5c0171cf749e
2022-01-04 09:06:15 -08:00
Michel Weststrate
b6c884f011 Make sure flipper server initialization errors are propagated properly
Summary:
This diff makes sure that errors are propagated similarly in flipper desktop and browser version, and that they are shown in either case.

Since in the browser version, the UI loads after the error happened, we'll store the error so that any client connecting in the future will read and report it.

Also added a `--failFast` flag to flipper-server, so that the process exits immediately if misconfigured, which is convenient in CI use cases and such

Reviewed By: nikoant

Differential Revision: D33348922

fbshipit-source-id: 0f584104f881141fde38da3f0031748415343ea2
2022-01-04 02:57:25 -08:00
Andres Suarez
79023ee190 Update copyright headers from Facebook to Meta
Reviewed By: bhamodi

Differential Revision: D33331422

fbshipit-source-id: 016e8dcc0c0c7f1fc353a348b54fda0d5e2ddc01
2021-12-27 14:31:45 -08:00
Michel Weststrate
cbda298b9d Add support to build flipper-server from SandCastle
Summary:
This refactors the flipper-server release script in such a way that it works the same as the normal release script, which solves two problems:

1) the official release script modifies versioned files, as it touches the package.json
2) it was slightly confusing that `flipper-server/static` was filled for release builds only, but not used in dev builds
3) running test:npx without running a release build before it, would fail with hard to comprehend errors. this has been solved now by removing that script and make it an arg of `build:flipper-server`

Also some further minor changes to prepare running a corresponding build / release job from SandCastle (later in this stack)

Reviewed By: nikoant

Differential Revision: D33297214

fbshipit-source-id: f6299aa982c3e59d1cc6479a93c56cbe4b57f85c
2021-12-24 07:18:11 -08:00
Michel Weststrate
72fa481d27 Fix generation of bundled.json, make source maps work in prod builds
Summary:
This diff fixes several issues around loading plugin, such as:

* make suresource maps work in the flipper-server production build
* make sure default plugins are no symlinked, which wouldn't work anywhere else but on the the system where it was build
* support release channel param for flipper-server

Bundled flipper-server is now 42MB (with icons (see later diffs) and plugins
```
ll flipper-server-v0.0.0.tgz
-rw-r--r--  1 mweststrate  staff    42M 23 Dec 15:29 flipper-server-v0.0.0.tgz
```

Reviewed By: nikoant

Differential Revision: D33294677

fbshipit-source-id: 63538dc8127f883fee6a3608673ad11ce239b350
2021-12-24 02:16:48 -08:00
Michel Weststrate
86b6d2c99d Make flipper-server NPX-able
Summary: Make sure flipper-server is bundled in such a way that it is self-contained NPX-able. Also added some checks to make sure that dev dependencies don't accidentallly end up in in Flipper buidls

Reviewed By: nikoant

Differential Revision: D33190254

fbshipit-source-id: 443162e537d8ca9f956acac2d7bd52cbf0c92172
2021-12-24 02:16:48 -08:00
Michel Weststrate
6ff4abbc67 Make flipper-server stand-alone servable
Summary:
This diff makes flipper-server stand-alone servable as a single package.

It basically works as follows:

- (default) plugins are build as usually into static folder
- static folder is copied into flipper-server/static (as far as relevant)
- `flipper-server/src/index.tsx` is bundled into `flipper-server/dist/index.js`
- `flipper-ui-browser/src/index.tsx` is bundled into `flipper-server/static/bundle.js`

If flipper-server is started without the `--bundler` config, the `bundle.js` will be served statically, rather than starting up the Metro bundler with all the typical transforms (in a distributed version of the package those all wouldn't resolve)

Things to be done in next diffs:

* make sure plugins actually load in the non bundled setup
* make sure flipper-server gets published properly
* make sure build is created as part of CI

At the end of this stack, running `npx flipper-server` on any machine should basically be a viable approach to get flipper up and running locally :)

Reviewed By: nikoant

Differential Revision: D33171107

fbshipit-source-id: 4af8ac2699467a0b55283fe084640482700744c2
2021-12-24 02:16:48 -08:00
Michel Weststrate
cea7be7fde Clean up globals
Summary: This diff is some boyscouting on cleaning up our globals, and stop using them inconsistently icmw global or window

Reviewed By: aigoncharov

Differential Revision: D33171108

fbshipit-source-id: 400893e5f31523631a7ab6fda428524c751901f1
2021-12-17 10:04:23 -08:00
Michel Weststrate
dcfeb4a4d5 Clean up packages and types
Summary:
This diff removes most deps from the root package.json, which now only contains electron and shared build / test infra structure: lint, prettier, jest, typescript.

This makes it possible to control much better which packages are used where, as all sub packages now have their deps explicitly in their package.json instead of incidentally shared. This allows for example to disable DOM types for all packages by default (flipper-plugin, ui(-core) and app still request it), and in the next diff I hope to add to this that nodeJS types are no longer shared either, so that UI oriented packages will generate compile errors when using Node built-ins

This diff removes most deps that were currently unused, and dedupes a bunch of other ones, so the build should probably be a bit smaller now as well:

{F686704253}

{F686704295}

Reviewed By: antonk52

Differential Revision: D33062859

fbshipit-source-id: 5afaa4f2103d055188382a3370c1fffa295a298a
2021-12-16 14:54:59 -08:00
Michel Weststrate
5ce5d897c8 Make loading of bundled plugins working and robust
Summary:
Bundled plugins so far didn't load because the defaultPlugins was not generated yet. Fixed follow up errors that resulted from node modules not being available in the browser, and made the process more robust so that one plugin that fails to initialise doesn't kill all bundled plugins from being loaded.

Cleaned up the server scripts, and reused the BUILTINS list that is already maintained in the babel transformer.

Report errors during the build process if modules are referred that are stubbed out (later on we could maybe error on that)

Reviewed By: aigoncharov

Differential Revision: D33020243

fbshipit-source-id: 3ce13b0049664b5fb19c1f45f0b33c1d7fdbea4c
2021-12-13 05:48:17 -08:00
Michel Weststrate
5564251aac Make sure only requests from own host & port are accepted for now
Summary: Make sure the flipper server socket only accepts local connections

Reviewed By: aigoncharov

Differential Revision: D33020251

fbshipit-source-id: 53e95e4871a45f3a3fa14f999499568a5a6b4995
2021-12-13 05:48:17 -08:00
Michel Weststrate
ac9080abac Remove 'process' usage
Summary: Removed process, adbkit and electron usages that were still remaining. Verified changes by disabling the built-in module stubbing (will be cleaned up further later in this stack).

Reviewed By: aigoncharov

Differential Revision: D33019083

fbshipit-source-id: 8bfce31f4b5ed349cb4fd86d34c9b41b9b8b8360
2021-12-13 05:48:17 -08:00
Michel Weststrate
3ef1923b29 Use uniform Socket message size to avoid disconnects
Summary: During startup the socket connection would close a few times, among others because Scribe dumps 1.3 MB of data after startup, and the maximum payload of `socket.io` defaults to 1MB. This diff changes it to 100MB (the max size used by `ws` library). We know that we need at least > 10 MB, as that is what plugins like Network cap at.

Reviewed By: aigoncharov

Differential Revision: D33017653

fbshipit-source-id: 1233af6fbdc4b9eed42786ee418cfd6d43b2b433
2021-12-13 05:48:17 -08:00
Michel Weststrate
73c6e8ee05 Make flipper server debuggable
Summary: This diffs adds debugging support to flipper server, by adding VSCode config for it

Reviewed By: timur-valiev, aigoncharov

Differential Revision: D32982874

fbshipit-source-id: 8e187ad05a05566a598db04b97e8b08e3de7e835
2021-12-13 05:48:16 -08:00
Michel Weststrate
ae56f2b62f change server build process to respect babel transforms
Summary:
The build process for the server was a simple ts-node that compiled all deps. However, that didn't do any source transformations we need, like replacing `fb-stubs` with `fb` in facebook builds.

This diff works out the dev build process to align more with how other parts of the code base is build, by starting metro to build and bundle the server (only the sources of flipper-server, flipper-server-core and other flipper packages are bundled, node-deps are left as is).

To achieve this, since metro doesn't have support for 'external' packages like any arbitrarily other bundler, we recycle the electronRequire work around that is used in the desktop app as well

Reviewed By: aigoncharov

Differential Revision: D32949677

fbshipit-source-id: 00d326bb17b68aece6fb43af98d0def13b335e74
2021-12-13 05:48:16 -08:00
Andrey Goncharov
e458ae76f9 Add exec Node API to FlipperLib
Summary: Changelog: Allow flipper plugins to run "exec" Node API on Flipper server.

Reviewed By: mweststrate

Differential Revision: D32881149

fbshipit-source-id: 46486a47ee9824ca68897c19fd86b4afc7f8bf1d
2021-12-10 06:36:12 -08:00
Michel Weststrate
92a743cc59 Processed some earlier review comments
Summary: Per title, processed some pending review comments made earlier in this stack

Reviewed By: aigoncharov

Differential Revision: D32916920

fbshipit-source-id: 01db85883596b5c85b77efc9cddadeac23cc4ef5
2021-12-08 04:30:57 -08:00