2023-07-19 09:58:37 +00:00
|
|
|
import crypto from 'node:crypto';
|
|
|
|
|
2024-02-21 10:02:59 +00:00
|
|
|
import * as bodyParser from 'body-parser';
|
2024-02-29 02:51:49 +00:00
|
|
|
import * as cookieParser from 'cookie-parser';
|
2020-12-07 20:12:50 +00:00
|
|
|
import express from 'express';
|
2022-09-09 14:53:28 +00:00
|
|
|
import { readFileSync } from 'fs';
|
2023-08-10 11:37:37 +00:00
|
|
|
import { createHandler } from 'graphql-http/lib/use/http';
|
2022-09-09 14:53:28 +00:00
|
|
|
import { createServer } from 'https';
|
|
|
|
import { join } from 'path';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
2022-02-28 15:28:02 +00:00
|
|
|
import { basicAuthRouter } from './basic-auth';
|
2022-03-18 09:57:12 +00:00
|
|
|
import githubApi from './github-api';
|
2022-06-01 08:39:31 +00:00
|
|
|
import gitlabApi from './gitlab-api';
|
2023-08-10 11:37:37 +00:00
|
|
|
import { schema } from './graphql';
|
2022-05-05 15:49:14 +00:00
|
|
|
import { startGRPCServer } from './grpc';
|
2023-09-24 23:12:50 +00:00
|
|
|
import insomniaApi from './insomnia-api';
|
2022-02-28 15:28:02 +00:00
|
|
|
import { oauthRoutes } from './oauth';
|
2022-09-09 14:53:28 +00:00
|
|
|
import { startWebSocketServer } from './websocket';
|
2020-12-07 20:12:50 +00:00
|
|
|
|
|
|
|
const app = express();
|
2024-02-29 02:51:49 +00:00
|
|
|
app.use(cookieParser.default());
|
2020-12-07 20:12:50 +00:00
|
|
|
const port = 4010;
|
2022-09-09 14:53:28 +00:00
|
|
|
const httpsPort = 4011;
|
2022-05-05 15:49:14 +00:00
|
|
|
const grpcPort = 50051;
|
2024-03-08 15:40:20 +00:00
|
|
|
const rawParser = bodyParser.raw({
|
|
|
|
inflate: true,
|
|
|
|
type: '*/*',
|
|
|
|
});
|
2020-12-07 20:12:50 +00:00
|
|
|
|
|
|
|
app.get('/pets/:id', (req, res) => {
|
|
|
|
res.status(200).send({ id: req.params.id });
|
|
|
|
});
|
|
|
|
|
2023-08-28 14:06:47 +00:00
|
|
|
app.get('/builds/check/*', (_req, res) => {
|
|
|
|
res.status(200).send({
|
|
|
|
url: 'https://github.com/Kong/insomnia/releases/download/core@2023.5.6/Insomnia.Core-2023.5.6.zip',
|
|
|
|
name: '2099.1.0',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-02-29 02:51:49 +00:00
|
|
|
async function echoHandler(req: any, res: any) {
|
|
|
|
res.status(200).send({
|
|
|
|
method: req.method,
|
|
|
|
headers: req.headers,
|
2024-03-08 15:40:20 +00:00
|
|
|
data: req.body.toString(),
|
2024-02-29 02:51:49 +00:00
|
|
|
cookies: req.cookies,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-03-08 15:40:20 +00:00
|
|
|
app.get('/echo', rawParser, echoHandler);
|
|
|
|
app.post('/echo', rawParser, echoHandler);
|
2024-02-21 10:02:59 +00:00
|
|
|
|
2021-11-17 09:44:19 +00:00
|
|
|
app.get('/sleep', (_req, res) => {
|
|
|
|
res.status(200).send({ sleep: true });
|
|
|
|
});
|
|
|
|
|
2022-02-04 12:20:21 +00:00
|
|
|
app.get('/cookies', (_req, res) => {
|
|
|
|
res
|
|
|
|
.status(200)
|
|
|
|
.header('content-type', 'text/plain')
|
|
|
|
.cookie('insomnia-test-cookie', 'value123')
|
|
|
|
.send(`${_req.headers['cookie']}`);
|
|
|
|
});
|
|
|
|
|
2021-10-06 22:01:43 +00:00
|
|
|
app.use('/file', express.static('fixtures/files'));
|
2020-12-07 20:12:50 +00:00
|
|
|
app.use('/auth/basic', basicAuthRouter);
|
|
|
|
|
2022-03-18 09:57:12 +00:00
|
|
|
githubApi(app);
|
2022-06-01 08:39:31 +00:00
|
|
|
gitlabApi(app);
|
2023-09-24 23:12:50 +00:00
|
|
|
insomniaApi(app);
|
2022-03-18 09:57:12 +00:00
|
|
|
|
ResponseTimer callstack exceeded (#3386)
* no default export (prepping for hooks)
* makes logic match other implementation
note that above in `componentDidUpdate` it uses `<= 0`, whereas here it uses `> 0` but then only checks for false.
Also, logically, there's no way to ever get `aria-hidden="true"` since it returns early so that entire attribute can just be removed.
* removes fake private class member syntax
this is moving to hooks anyway, but in the meantime...
* undoes calling identical code twice in a row...
* condenses class methods to prepare for hooks
* hooks refactor
fairly faithful to the original, this attempts to just refactor to hooks. this exposes, again, the fact that we're setting state within useEffect.
* removes 200 ms offset for response time
so that, now, you know, the time reported is the actual time.
* adds logging for response timer lage
* removes timer logging and `responseTime` prop after PR discussion
it's definitely fruitful, but the fix for the callstack exceeded is what needs to be the focus.
* removes shadowed variable per PR feedback
* reinstates and documents 200ms compensation
* add delay endpoint to example server
* Update packages/insomnia-app/app/ui/components/response-timer.tsx
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-17 23:58:05 +00:00
|
|
|
app.get('/delay/seconds/:duration', (req, res) => {
|
2021-05-19 11:49:48 +00:00
|
|
|
const delaySec = Number.parseInt(req.params.duration || '2');
|
2023-12-14 08:03:26 +00:00
|
|
|
setTimeout(() => {
|
2021-05-27 18:00:32 +00:00
|
|
|
res.send(`Delayed by ${delaySec} seconds`);
|
ResponseTimer callstack exceeded (#3386)
* no default export (prepping for hooks)
* makes logic match other implementation
note that above in `componentDidUpdate` it uses `<= 0`, whereas here it uses `> 0` but then only checks for false.
Also, logically, there's no way to ever get `aria-hidden="true"` since it returns early so that entire attribute can just be removed.
* removes fake private class member syntax
this is moving to hooks anyway, but in the meantime...
* undoes calling identical code twice in a row...
* condenses class methods to prepare for hooks
* hooks refactor
fairly faithful to the original, this attempts to just refactor to hooks. this exposes, again, the fact that we're setting state within useEffect.
* removes 200 ms offset for response time
so that, now, you know, the time reported is the actual time.
* adds logging for response timer lage
* removes timer logging and `responseTime` prop after PR discussion
it's definitely fruitful, but the fix for the callstack exceeded is what needs to be the focus.
* removes shadowed variable per PR feedback
* reinstates and documents 200ms compensation
* add delay endpoint to example server
* Update packages/insomnia-app/app/ui/components/response-timer.tsx
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-17 23:58:05 +00:00
|
|
|
}, delaySec * 1000);
|
2021-05-19 11:49:48 +00:00
|
|
|
});
|
2022-02-28 15:28:02 +00:00
|
|
|
|
2024-04-05 15:22:10 +00:00
|
|
|
oauthRoutes(port).then(router => app.use('/oidc', router));
|
2022-02-28 15:28:02 +00:00
|
|
|
|
2022-03-18 09:57:12 +00:00
|
|
|
app.get('/', (_req, res) => {
|
|
|
|
res.status(200).send();
|
|
|
|
});
|
|
|
|
|
2023-08-10 11:37:37 +00:00
|
|
|
app.all('/graphql', createHandler({ schema }));
|
|
|
|
|
2023-07-07 12:36:41 +00:00
|
|
|
app.use(express.json()); // Used to parse JSON bodies
|
|
|
|
|
|
|
|
// SSE routes
|
|
|
|
let subscribers: { id: string; response: express.Response }[] = [];
|
|
|
|
app.get('/events', (request, response) => {
|
|
|
|
const headers = {
|
|
|
|
'Content-Type': 'text/event-stream',
|
|
|
|
'Connection': 'keep-alive',
|
|
|
|
'Cache-Control': 'no-cache',
|
|
|
|
};
|
|
|
|
response.writeHead(200, headers);
|
|
|
|
const subscriberId = crypto.randomUUID();
|
|
|
|
const data = `data: ${JSON.stringify({ id: subscriberId })}\n\n`;
|
|
|
|
response.write(data);
|
|
|
|
const subscriber = {
|
|
|
|
id: subscriberId,
|
|
|
|
response,
|
|
|
|
};
|
|
|
|
subscribers.push(subscriber);
|
2023-07-19 09:58:37 +00:00
|
|
|
setInterval(() => {
|
|
|
|
// const id = subscriberId;
|
|
|
|
const data = JSON.stringify({ message: 'Time: ' + new Date().toISOString().slice(11, 19) });
|
|
|
|
// response.write('id: ' + id + '\n');
|
|
|
|
response.write('data: ' + data + '\n\n');
|
|
|
|
}, 1000);
|
2023-07-07 12:36:41 +00:00
|
|
|
request.on('close', () => {
|
|
|
|
console.log(`${subscriberId} Connection closed`);
|
|
|
|
subscribers = subscribers.filter(sub => sub.id !== subscriberId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
app.post('/send-event', (request, response) => {
|
|
|
|
// Requires middleware to parse JSON body
|
|
|
|
console.log('Received event', request.body);
|
|
|
|
subscribers.forEach(subscriber => subscriber.response.write(`data: ${JSON.stringify(request.body)}\n\n`));
|
|
|
|
response.json({ success: true });
|
|
|
|
});
|
2022-06-22 15:29:27 +00:00
|
|
|
|
2022-12-07 10:33:15 +00:00
|
|
|
startWebSocketServer(app.listen(port, () => {
|
|
|
|
console.log(`Listening at http://localhost:${port}`);
|
|
|
|
console.log(`Listening at ws://localhost:${port}`);
|
|
|
|
}));
|
2022-09-09 14:53:28 +00:00
|
|
|
|
2022-12-07 10:33:15 +00:00
|
|
|
startWebSocketServer(createServer({
|
|
|
|
cert: readFileSync(join(__dirname, '../fixtures/certificates/localhost.pem')),
|
|
|
|
key: readFileSync(join(__dirname, '../fixtures/certificates/localhost-key.pem')),
|
|
|
|
}, app).listen(httpsPort, () => {
|
|
|
|
console.log(`Listening at https://localhost:${httpsPort}`);
|
|
|
|
console.log(`Listening at wss://localhost:${httpsPort}`);
|
|
|
|
}));
|
2022-09-09 14:53:28 +00:00
|
|
|
|
2022-12-07 10:33:15 +00:00
|
|
|
startGRPCServer(grpcPort);
|