Skip to content

Commit

Permalink
Fix dev server (#5333)
Browse files Browse the repository at this point in the history
* Fix dev server

* Clean up
  • Loading branch information
compulim authored Oct 25, 2024
1 parent 51385f7 commit e6bfd8a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 135 deletions.
145 changes: 125 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
"precommit:eslint": "../../node_modules/.bin/eslint --report-unused-disable-directives --max-warnings 0",
"precommit:typecheck": "tsc --project ./src --emitDeclarationOnly false --esModuleInterop true --noEmit --pretty false",
"preversion": "cat package.json | jq '(.localDependencies // {} | to_entries | map([if .value == \"production\" then \"dependencies\" else \"devDependencies\" end, .key])) as $P | delpaths($P)' > package-temp.json && mv package-temp.json package.json",
"start": "concurrently --kill-others --prefix-colors \"auto\" \"npm:start:*\"",
"start:devserver": "node ./scripts/devServer.mjs",
"start:tsup": "npm run build:tsup -- --watch"
"start": "npm run build:tsup -- --watch"
},
"localDependencies": {
"botframework-directlinespeech-sdk": "production",
Expand Down
8 changes: 0 additions & 8 deletions packages/bundle/scripts/.eslintrc.yml

This file was deleted.

52 changes: 0 additions & 52 deletions packages/bundle/scripts/devServer.mjs

This file was deleted.

5 changes: 1 addition & 4 deletions packages/test/dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
]
},
"devDependencies": {
"chalk": "^5.3.0",
"compression": "^1.7.4",
"express": "^4.19.2",
"http-proxy-middleware": "^2.0.6",
"serve-handler": "^6.1.5"
},
"dependencies": {}
}
}
54 changes: 6 additions & 48 deletions packages/test/dev-server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import chalk from 'chalk';
import compression from 'compression';
import express from 'express';
import { readFile } from 'fs/promises';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { resolve } from 'path';
import serve from 'serve-handler';
import { fileURLToPath } from 'url';

const { ESBUILD_TARGET = 'http://127.0.0.1:8000/', PORT = 5001 } = process.env;
const { PORT = 5001 } = process.env;
const resolveFromProjectRoot = resolve.bind(undefined, fileURLToPath(import.meta.url), '../../');
const resolveFromRepositoryRoot = resolveFromProjectRoot.bind(undefined, '../../../');

Expand Down Expand Up @@ -64,72 +62,32 @@ const resolveFromRepositoryRoot = resolveFromProjectRoot.bind(undefined, '../../
app.use(
'/__dist__/fluent-bundle.development.js',
express.static(
resolve(
fileURLToPath(import.meta.url),
'../../../../test/fluent-bundle/dist/fluent-bundle.development.js'
)
resolve(fileURLToPath(import.meta.url), '../../../../test/fluent-bundle/dist/fluent-bundle.development.js')
)
);

app.use(
'/__dist__/fluent-bundle.development.js.map',
express.static(
resolve(
fileURLToPath(import.meta.url),
'../../../../test/fluent-bundle/dist/fluent-bundle.development.js.map'
)
resolve(fileURLToPath(import.meta.url), '../../../../test/fluent-bundle/dist/fluent-bundle.development.js.map')
)
);

app.use(
'/__dist__/fluent-bundle.production.min.js',
express.static(
resolve(
fileURLToPath(import.meta.url),
'../../../../test/fluent-bundle/dist/fluent-bundle.production.min.js'
)
resolve(fileURLToPath(import.meta.url), '../../../../test/fluent-bundle/dist/fluent-bundle.production.min.js')
)
);

app.use(
'/__dist__/fluent-bundle.production.min.js.map',
express.static(
resolve(
fileURLToPath(import.meta.url),
'../../../../test/fluent-bundle/dist/fluent-bundle.production.min.js.map'
)
resolve(fileURLToPath(import.meta.url), '../../../../test/fluent-bundle/dist/fluent-bundle.production.min.js.map')
)
);

// /__dist__/ will be serve from ESBuild development server.
app.use(
'/__dist__/',
createProxyMiddleware({
changeOrigin: true,
logLevel: 'warn',
pathRewrite: { '^\\/__dist__\\/': '/' },
onProxyReq(_proxyReq, _req, res) {
res.setHeader('x-request-time', new Date().toISOString());
},
onProxyRes(_, req, res) {
const duration = Date.now() - new Date(res.getHeader('x-request-time'));
const durationString = `(${duration} ms)`;

console.log(
`${req.url} ${
duration < 1000
? chalk.greenBright(durationString)
: duration < 2000
? chalk.yellowBright(durationString)
: chalk.redBright(durationString)
}`
);

res.removeHeader('x-request-time');
},
target: ESBUILD_TARGET
})
);
app.use('/__dist__/webchat*', express.static(resolve(fileURLToPath(import.meta.url), '../../../bundle/dist')));

// Other requests will be served by `serve-handler` based on `/serve-test.json`.
app.use((req, res) => serve(req, res, { ...serveConfigJSON, public: resolveFromRepositoryRoot() }));
Expand Down

0 comments on commit e6bfd8a

Please sign in to comment.