question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[dev-server] Use dev-server as middleware for Express

See original GitHub issue

I am using dev-server to serve a local project without having to build each time. In order for my application to actually work, I need to define routes within the server.

I wrote this tiny function which will basically enrich app (which is an Express object) so that I add es-dev-server as Express routes. I do that by creating the server manually with createConfig, and then creating a Koa app, and use koaApp.callback() to convert the koa app into an Express one. It works beautifully, and we are on the verge of releasing all of this under a free license.

However, as I understand es-dev-server is no more… I was hoping you could let me know if this code is still functional (that is, es-dev-server and es-server share the same API) or if I need to change things around. Or, if what I am doing can be done with es-dev-server.

Thank you for the awesome work.

exports = module.exports = function (app) {

    const Koa = require('koa')
    const config = esDevServer.createConfig({
      nodeResolve: true,
      appIndex: 'index.html',
      moduleDirs: ['node_modules'],
      preserveSymlinks: true
    })
    const middlewares = esDevServer.createMiddlewares(config)
    const koaApp = new Koa()
    middlewares.forEach(middleware => {
      koaApp.use(middleware)
    })

    app.use(koaApp.callback())
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mercmobilycommented, Sep 23, 2020

One thing I don’t quite get… we have gorgeous ES6 which doesn’t require building or anything. I can understand Typescript in cases where you have a huge software project and typing actually helps, but… why typescript for something like the es-dev-server…? I guess it’s totally the dev’s choice, and it depends on what they are comfortable with. But I do wish I were looking at ES6 code right now.

0reactions
mercmobilycommented, Feb 10, 2021

Sorry about the noise. I wanted to add that I added literate documentation to the ~150 lines of code that make up the program.

Since you have vast experience in writing this, and if you have spare time, I would love to know where I can improve on it (e.g. use cases I didn’t predict,possible pitfalls, etc.). If not, all good.

If others are requesting such a feature (see: using web-dev-server as Express middleware), feel free to distribute/rebrand es6-dev-server as you like.

I hope this helped!

https://github.com/mobily-enterprises/es6-dev-server/blob/main/index.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run webpack-dev-server on express
Use webpack-dev-middleware and webpack-hot-middleware on express. Let's get started. (1) Project creation. Create a project from scratch ...
Read more >
Running a node express server using webpack-dev-server
Just use http-proxy-middleware in Express to proxy all requests that the server doesn't itself handle to the webpack-dev-server:
Read more >
Building a Dev Server with Express and Webpack
I recently built my first React app without using the create-react-app command, and — riding a wave of JavaScript confidence from the ...
Read more >
How to run webpack-dev-server on express. - GitHub
How to run webpack-dev-server on express.Auto reloading (live reload) using webpack-dev-middleware and webpack-hot-middleware.
Read more >
DevServer - webpack
DevServer. webpack-dev-server can be used to quickly develop an application. See the development guide to get started. This page describes the options that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found