• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coderaiser / cloudcmd / 26469338489

26 May 2026 07:08PM UTC coverage: 49.248% (+0.5%) from 48.774%
26469338489

push

github

coderaiser
feature: cloudcmd: ratelimit: X-Forwarded-For (#437)

347 of 440 branches covered (78.86%)

35 of 57 new or added lines in 3 files covered. (61.4%)

13 existing lines in 2 files now uncovered.

3800 of 7716 relevant lines covered (49.25%)

9.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/server/server.js
1
import http from 'node:http';
3✔
2
import {promisify} from 'node:util';
3✔
3
import process from 'node:process';
3✔
4
import {rateLimit} from 'express-rate-limit';
3✔
5
import currify from 'currify';
3✔
6
import squad from 'squad';
3✔
7
import {tryToCatch} from 'try-to-catch';
3✔
8
import opn from 'open';
3✔
9
import express from 'express';
3✔
10
import {Server} from 'socket.io';
3✔
11
import wraptile from 'wraptile';
3✔
12
import compression from 'compression';
3✔
13
import tryRequire from 'tryrequire';
3✔
14
import {cloudcmd} from '#server/cloudcmd';
3✔
15
import exit from './exit.js';
3✔
16

3✔
17
const RATE_LIMIT = 1000;
3✔
18
const RATE_WINDOW = 15 * 60 * 1000;
3✔
19

3✔
20
const bind = (f, self) => f.bind(self);
3✔
21

3✔
22
const two = currify((f, a, b) => f(a, b));
3✔
23
const shutdown = wraptile(async (config, promises) => {
3✔
NEW
24
    if (config('log'))
×
NEW
25
        console.log('closing cloudcmd...');
×
NEW
26
    
×
27
    await Promise.all(promises);
×
28
    process.exit(0);
×
29
});
3✔
30

3✔
31
const promisifySelf = squad(promisify, bind);
3✔
32

3✔
33
const exitPort = two(exit, 'cloudcmd --port: %s');
3✔
34

3✔
35
const logger = tryRequire('morgan');
3✔
36

3✔
37
export default async (options, config) => {
3✔
38
    const prefix = config('prefix');
3✔
39
    const port = process.env.PORT /* c9           */ || config('port');
3!
40
    
3✔
41
    const ip = process.env.IP /* c9           */ || config('ip') || '0.0.0.0';
3✔
42
    
3✔
43
    const app = express();
3✔
44
    const server = http.createServer(app);
3✔
45
    
3✔
46
    if (config('log') && logger)
3!
47
        app.use(logger('dev'));
3!
48
    
3✔
49
    if (prefix)
3✔
50
        app.get('/', (req, res) => res.redirect(`${prefix}/`));
3!
51
    
3✔
52
    const socketServer = new Server(server, {
3✔
53
        path: `${prefix}/socket.io`,
3✔
54
    });
3✔
55
    
3✔
56
    const limiter = rateLimit({
3✔
57
        windowMs: RATE_WINDOW,
3✔
58
        limit: RATE_LIMIT,
3✔
59
    });
3✔
60
    
3✔
61
    app.set('trust proxy', 1);
3✔
62
    
3✔
63
    app.use(compression());
3✔
64
    app.use(limiter);
3✔
65
    app.use(prefix, cloudcmd({
3✔
66
        config: options,
3✔
67
        socket: socketServer,
3✔
68
        configManager: config,
3✔
69
    }));
3✔
70
    
3✔
71
    if (port < 0 || port > 65_535)
3✔
72
        return exitPort('port number could be 1..65535, 0 means any available port');
3!
73
    
3✔
74
    const listen = promisifySelf(server.listen, server);
3✔
75
    const closeServer = promisifySelf(server.close, server);
3✔
76
    const closeSocket = promisifySelf(socketServer.close, socketServer);
3✔
77
    
3✔
78
    server.on('error', exitPort);
3✔
79
    await listen(port, ip);
3✔
80
    
3✔
81
    const close = shutdown(config, [closeServer, closeSocket]);
3✔
82
    
3✔
83
    process.on('SIGINT', close);
3✔
84
    process.on('SIGUSR1', close);
3✔
85
    
3✔
86
    const host = config('ip') || 'localhost';
3✔
87
    const port0 = port || server.address().port;
3!
88
    const url = `http://${host}:${port0}${prefix}/`;
3✔
89
    
3✔
90
    if (config('log'))
3✔
91
        console.log(`url: ${url}`);
3!
92
    
3✔
93
    if (!config('open'))
3✔
94
        return;
3!
95
    
3✔
96
    const [openError] = await tryToCatch(opn, url);
3✔
97
    
3✔
98
    if (openError)
3✔
99
        console.error('cloudcmd --open:', openError.message);
3!
100
};
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc