Comments (8)
If you send the response yourself, make sure to return the response object from your controller. That way the framework knows you handled the response yourself and won't try to send it again.
from routing-controllers.
Never seen this issue before, tho I’ve never tried with esbuild. I’m not sure if it is resolved but esbuild did not support reflect metadata in the past. Could you include the whole source you want to compile or setup a repro repo?
from routing-controllers.
Esbuild doesn't really support decorators, so I wrote a manual check for it:
// naively check if @ is present
function hasDecorator(fileContent, offset = 0) {
const atPosition = fileContent.indexOf("@", offset);
if (atPosition === -1) {
return false;
}
if (atPosition === 1) {
return true;
}
// ignore "@ and '@ as they are used in require('@org/repo')
if (["'", '"'].includes(fileContent.substr(atPosition - 1, 1))) {
return hasDecorator(fileContent, atPosition + 1);
}
return true;
}`
Which then checks the following:
const serverConfig = Object.assign({}, config, {
entry: "./src/server/main.ts",
module: {
rules: [
{
test: /\.tsx?$/,
oneOf: [
{
test: (filePath) => {
if (!filePath) {
return false;
}
try {
const fileContent = fs.readFileSync(filePath).toString();
return !hasDecorator(fileContent);
} catch (e) {
return false;
}
},
use: [
{
loader: "esbuild-loader",
},
],
},
{
use: [
{
loader: "ts-loader",
options: { transpileOnly: true },
},
],
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".json"],
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "../server/packages/gamemode"),
},
target: "node",
devtool: "source-map",
plugins: [new webpack.BannerPlugin(fs.readFileSync("./LICENSE.md", "utf8"))],
stats: {
warnings: false,
},
});
I'm not sure if that's the cause?
from routing-controllers.
My best guess is that no tree shaking happens in your build. So even tho your app does not use koa, it includes it in the build because it's part of the package. Does this happen if you use tsc only?
from routing-controllers.
Looking at some blog posts, they do mention it's possible:
https://www.hotovo.com/blog/speeding-up-webpack-builds-with-esbuild
Just wondering right, would there be a chance to also get like lightweight packages that don't rely on like a Koa for Express and no Express for Koa variants? Meaning the package from the build has no Koa/Express included depending on your npm install. So if we do the npm install for an Express variant only, the drivers of Koa and all don't come along etc.
from routing-controllers.
With tsc they don’t rely on the other framework because if it’s not used it’s omitted. The parent frameworks are included dynamically based on what you use. I have routing-controllers running in prod for multiple projects with express and we don’t have koa installed.
from routing-controllers.
It looks like Tsc did indeed the trick @attilaorosz ! Converted it all and it seems to work now. Only issue I am now receiving is the following:
UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:543:11)
Code is as follows:
@JsonController()
@injectable()
export class InformationController {
constructor(@inject("IInformationService") private informationService: IInformationService) {}
@Get("/test")
gatherInformation(@Req() request: any, @Res() response: any) {
try {
response.send("Success");
} catch (error: any) {
response.status(500).send("Something broke!");
}
}
}
Got a clue why? The response returns Success correctly, yet it throws the warning.
from routing-controllers.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from routing-controllers.
Related Issues (20)
- fix: global middlewares (re)registered each time useExpressServer is called HOT 3
- question: @Param not type casted HOT 21
- fix: class-validator does not work on last version of RC HOT 9
- fix: <Injected Response object is undefined> HOT 1
- question: @Get path with literal and variable HOT 3
- feature: <how make sub folder controllers> how make sub folder controllers HOT 2
- fix: jsdoc for Put http method, it mentions POST http method
- fix: TypeDI do not inject service HOT 1
- Annotate return type of `createExpressServer` with more narrow type HOT 1
- `cors: true` causes "Cannot set headers after they are sent to the client" error HOT 3
- fix: Global middlewares are not used if route prefix doesn't start with a slash ("/")
- fix: TypeError this.targetType.toLowerCase is not a function HOT 3
- fix: import statements should not affect the route matching order
- Can we create multiple paths for the same controller function? HOT 7
- fix: CJS being imported instead of ESM when trying to load controllers from directory import HOT 4
- feature: Allow to use `app.use(createExpressRouter())` instead of `useExpressServer(app)` HOT 6
- question: Routes with path parameters continue middleware chain (but those without, don't)? HOT 5
- feature: Dynamic route HOT 5
- feature: Introduce Generics to CurrentUserChecker for Enhanced Type Safety HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routing-controllers.