Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Decorator] Static #12

Closed
alexproca opened this issue Dec 11, 2016 · 7 comments
Closed

[Decorator] Static #12

alexproca opened this issue Dec 11, 2016 · 7 comments
Assignees

Comments

@alexproca
Copy link
Contributor

If we want to add some static resources we have to:

this.getExpressApp()
            .use(Express.static('./app'))
            .get('*', (req, res) => {
                res.sendFile(__dirname + '/app/index.html')
            })

It would be nice to add static resources from decorators. This decorator could be added to server.

Example:

@Static({
  '/': './app',
  '/css', './css-files'
})
export Server extends ServerLoader {
......
}
@Romakita
Copy link
Collaborator

Romakita commented Dec 12, 2016

The module serve-static can do that. No ?

class ServerLoader {
     $onMountingMiddlewares(){
           const serveStatic =   require('serve-static');
           this.getExpressApp()
                 .use(serveStatic('app'))
                 .use('/css', serveStatic('css-files'));
     }
}

@alexproca
Copy link
Contributor Author

Yes it can do it and it will do it. The proposal is only syntactic sugar. If one have to implement this he have to be careful with __directory because the path should be absolute, to use Path.resolve and so on. This would be very intuitive; you only have to add the route and the directory. May be even extended to nested static routes:

@Static({
  '/css': {
    'old': './old-css-files',
    'new': './new-css-files'
  },
  'public': './public'
})

Usually syntactic sugar shrinks the room for errors. ;)

@Romakita
Copy link
Collaborator

Ok Alex :) you can propose your implementation of this decorator !

@alexproca
Copy link
Contributor Author

Sure you can assign it to me! I will do it at the end of the week. I always wanted to extract express utils in a library like this but somehow managed not to do it. Your project is exactly the right thing I needed for migrating an older project in the brave new world of typescript.

@Romakita
Copy link
Collaborator

You are assigned to this task :D

@alexproca
Copy link
Contributor Author

Cool thanks. You can assign #13 to me too.

@Romakita
Copy link
Collaborator

Romakita commented Feb 27, 2017

Implemented with the new decorator

@ServerSettings({
   "serveStatic": {
      "\": "webapp"
   }
})
class Server extends ServerLoader {}

@Romakita Romakita self-assigned this Feb 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants