nstantpage-agent 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/cli.js +1 -0
- package/dist/commands/login.js +9 -0
- package/dist/commands/start.d.ts +1 -0
- package/dist/commands/start.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ npx nstantpage-agent start
|
|
|
90
90
|
| `-p, --port <port>` | `3000` | Local dev server port |
|
|
91
91
|
| `-a, --api-port <port>` | `18924` | Internal API port |
|
|
92
92
|
| `--project-id <id>` | — | Link to a specific project |
|
|
93
|
+
| `--token <token>` | — | Auth token (skip login flow) |
|
|
93
94
|
| `--gateway <url>` | `wss://webprev.live` | Gateway URL |
|
|
94
95
|
| `--no-dev` | — | Don't start dev server automatically |
|
|
95
96
|
|
|
@@ -157,7 +158,9 @@ node dist/cli.js start . --project-id test --gateway ws://localhost:4000
|
|
|
157
158
|
## Troubleshooting
|
|
158
159
|
|
|
159
160
|
### "Not authenticated" error
|
|
160
|
-
Run `npx nstantpage-agent login` to authenticate.
|
|
161
|
+
Run `npx nstantpage-agent login` to authenticate (opens browser).
|
|
162
|
+
Or pass your token directly: `npx nstantpage-agent start --token YOUR_TOKEN --project-id 1234`
|
|
163
|
+
For local gateway testing, auth is skipped automatically when using `--gateway ws://localhost:4000`.
|
|
161
164
|
|
|
162
165
|
### Port already in use
|
|
163
166
|
Use `--port` and `--api-port` flags to change ports:
|
package/dist/cli.js
CHANGED
|
@@ -33,6 +33,7 @@ program
|
|
|
33
33
|
.option('-a, --api-port <port>', 'Local API server port (internal)', '18924')
|
|
34
34
|
.option('--project-id <id>', 'Link to a specific project ID')
|
|
35
35
|
.option('--gateway <url>', 'Gateway URL', 'wss://webprev.live')
|
|
36
|
+
.option('--token <token>', 'Auth token (skip login flow)')
|
|
36
37
|
.option('--no-dev', 'Skip starting the dev server (start manually later)')
|
|
37
38
|
.action(startCommand);
|
|
38
39
|
program
|
package/dist/commands/login.js
CHANGED
|
@@ -19,6 +19,15 @@ export async function loginCommand() {
|
|
|
19
19
|
const callbackPort = 18923;
|
|
20
20
|
const token = await new Promise((resolve, reject) => {
|
|
21
21
|
const server = http.createServer((req, res) => {
|
|
22
|
+
// Allow CORS from nstantpage.com (the auth page uses fetch())
|
|
23
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
24
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
25
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
26
|
+
if (req.method === 'OPTIONS') {
|
|
27
|
+
res.writeHead(204);
|
|
28
|
+
res.end();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
22
31
|
const url = new URL(req.url, `http://localhost:${callbackPort}`);
|
|
23
32
|
const token = url.searchParams.get('token');
|
|
24
33
|
if (token) {
|
package/dist/commands/start.d.ts
CHANGED
package/dist/commands/start.js
CHANGED
|
@@ -20,12 +20,22 @@ import { TunnelClient } from '../tunnel.js';
|
|
|
20
20
|
import { LocalServer } from '../localServer.js';
|
|
21
21
|
export async function startCommand(directory, options) {
|
|
22
22
|
const conf = getConfig();
|
|
23
|
+
// If --token was passed, persist it
|
|
24
|
+
if (options.token) {
|
|
25
|
+
conf.set('token', options.token);
|
|
26
|
+
}
|
|
23
27
|
// Check authentication
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
// Allow unauthenticated connections to local gateways (ws://localhost, ws://127.0.0.1)
|
|
29
|
+
const isLocalGateway = /^wss?:\/\/(localhost|127\.0\.0\.1)/.test(options.gateway);
|
|
30
|
+
let token = conf.get('token');
|
|
31
|
+
if (!token && !isLocalGateway) {
|
|
26
32
|
console.log(chalk.red('✗ Not authenticated. Run "nstantpage login" first.'));
|
|
33
|
+
console.log(chalk.gray(' Or pass --token <your-token> to authenticate inline.'));
|
|
27
34
|
process.exit(1);
|
|
28
35
|
}
|
|
36
|
+
if (!token && isLocalGateway) {
|
|
37
|
+
token = 'local-dev';
|
|
38
|
+
}
|
|
29
39
|
// Resolve project directory
|
|
30
40
|
const projectDir = path.resolve(directory);
|
|
31
41
|
if (!fs.existsSync(projectDir)) {
|
package/package.json
CHANGED