Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const server = http.createServer(async (req, res) => {
const url = req.url || '/'
// handle statics
if (isStatic(url)) {
return serveHandler(req, res, {
public: path.resolve(__dirname, PUB_DIR),
headers: serveStaticHeaders
})
}
// redirects `/docs/:name` to `/:name`
if (url.startsWith('/docs/')) {
return sendRedirection(res, 301, url.replace('/docs', ''))
}
// handle endpoints
const handlerName = badgeNames.find(h => matchRoute(`/${h}/:path*`, url))
try {
if (handlerName) {
const handlerPath = path.join(__dirname, 'api', handlerName)
const httpServer = createServer((req, res) =>
handler(req, res, {
redirects: [
{ source: '/', destination: '__tests__/setup/web/index.html' },
{
source: '/createProduceConsumeBroker.js',
destination: '__tests__/setup/web/createProduceConsumeBroker.js'
},
{ source: '/mockWebSpeech.js', destination: '__tests__/setup/web/mockWebSpeech.js' }
],
rewrites: [
{ source: '/webchat.js', destination: 'packages/bundle/dist/webchat.js' },
{ source: '/webchat-es5.js', destination: 'packages/bundle/dist/webchat-es5.js' },
{ source: '/webchat-instrumented.js', destination: 'packages/bundle/dist/webchat-instrumented.js' },
{ source: '/webchat-instrumented-es5.js', destination: 'packages/bundle/dist/webchat-instrumented-es5.js' },
{
source: '/webchat-instrumented-minimal.js',
destination: 'packages/bundle/dist/webchat-instrumented-minimal.js'
server.get('/**/*', (req, res) => {
serveHandler(req, res, {
public: join(__dirname, '../_site')
});
});
this.server = http.createServer((request, response) =>
handler(request, response, {
public: this.directory,
cleanUrls: false,
headers: [
{
source: '**',
headers: [
{
key: 'Cache-Control',
value: 'no-cache, no-store, must-revalidate',
},
],
},
],
}),
);
function serveStaticFile(
req: http.IncomingMessage,
res: http.ServerResponse,
cwd: string,
opts?: object
) {
return serveHandler(req, res, {
public: cwd,
cleanUrls: false,
etag: true,
...opts
});
}
server.get('/public/*', async (req, res) => {
if ('slow' in req.query) {
res.noCache();
const release = await acquireSlowQueue();
await delay(1000);
release();
}
await serveHandler(req, res, {
path: join(__dirname, './public')
});
});
function serveStaticFile(
req: http.IncomingMessage,
res: http.ServerResponse,
cwd: string,
opts?: object
) {
return serveHandler(req, res, {
public: cwd,
cleanUrls: false,
etag: true,
...opts,
});
}
const server = http.createServer((request: any, response: any) => {
return handler(request, response, {
cleanUrls: true,
trailingSlash: false,
public: options.public
});
});
base
};
});
if (files.length === 0) {
return false;
}
const directory = `/${prefix}`;
const paths = [
{
name: directory,
url: requestPath
}
];
const directoryHtml = directoryTemplate({
files,
paths,
directory
});
this.setResponseHeaders(res, nowRequestId);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader(
'Content-Length',
String(Buffer.byteLength(directoryHtml, 'utf8'))
);
res.end(directoryHtml);
return true;
}
base,
};
});
if (files.length === 0) {
return false;
}
const directory = `/${prefix}`;
const paths = [
{
name: directory,
url: requestPath,
},
];
const directoryHtml = directoryTemplate({
files,
paths,
directory,
});
this.setResponseHeaders(res, nowRequestId);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader(
'Content-Length',
String(Buffer.byteLength(directoryHtml, 'utf8'))
);
res.end(directoryHtml);
return true;
}