This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post("/", (req, res) => { | |
User.findOne({email: req.body.email}).then(user => { | |
//do something | |
}).catch(err => { | |
require("../../logger")(req).report(err); | |
});; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File: A.js | |
console.log("In A.js"); | |
class A { | |
construtor() { | |
//some logic | |
} | |
} | |
module.exports = A; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Placing this before the RegisterServiceAsync is enough for the migrations to work | |
//No need to pass any arguments | |
BuildWebHost(new string[] { }).Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IWebHost BuildWebHost(string[] args) | |
{ | |
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddDbContext<AppDbContext>(options => | |
{ | |
options.UseSqlServer(Configuration.GetConnectionString("ToDos")); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppDbContext : DbContext | |
{ | |
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) | |
{ | |
} | |
public DbSet<ToDo> ToDos { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.AsyncWrapper = function AsyncWrapper(fn) { | |
return (req, res, next) => { | |
return fn(req, res).catch(next); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {RequestHandler} from 'express'; | |
export function AsyncWrapper(fn: RequestHandler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface RequestHandler { | |
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2 | |
(req: Request, res: Response, next: NextFunction): any; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Assume it's in the same folderconst asyncWrapper = require("./async-wrapper"); | |
app.post("/path/to/endpoint", asyncWrapper(async (req, res) => { | |
//Do something like setting a header | |
res.setHeader("Content-type", "application/json"); | |
})); |
NewerOlder