express-serve-static-core#Response TypeScript Examples
The following examples show how to use
express-serve-static-core#Response.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuthFlowError.ts From ADR-Gateway with MIT License | 6 votes |
SendOAuthError = (Simulated:boolean,res:Response, redirect_uri:string, state:string, error: string, error_description?: string) => {
let responseData:any = _.omitBy({
state,
error,
error_description: error_description !== "" ? error_description : undefined,
}, _.isNil);
let fragment = _.map(responseData,(v,k) => encodeURIComponent(k)+"="+encodeURIComponent(v)).join("&")
let newUrl = redirect_uri + "#" + fragment;
if (Simulated) {
return res.json(newUrl)
} else {
return res.header('x-redirect-alt-location',newUrl).redirect(newUrl)
}
}
Example #2
Source File: http-server.ts From homebridge-zigbee-nt with Apache License 2.0 | 6 votes |
function middleware(publicURL: string, logger: winston.Logger) {
function logAccessIfVerbose(req) {
const protocol = req.connection.encrypted ? 'https' : 'http';
const fullUrl = `${protocol}://${req.headers.host}${req.url}`;
logger.debug(`Request: ${fullUrl}`);
}
return function (req: Request, res: Response, next: NextFunction) {
logAccessIfVerbose(req);
function send404() {
if (next) {
return next();
}
setHeaders(res);
res.writeHead(404);
res.end();
}
function sendIndex() {
req.url = `/${path.basename('index.html')}`;
serve(req, res, send404);
}
const { pathname } = url.parse(req.url);
if (pathname.startsWith('/api')) {
next();
} else if (!pathname.startsWith(publicURL) || path.extname(pathname) === '') {
// If the URL doesn't start with the public path, or the URL doesn't
// have a file extension, send the main HTML bundle.
return sendIndex();
} else {
// Otherwise, serve the file from the dist folder
req.url = pathname.slice(publicURL.length);
return serve(req, res, sendIndex);
}
};
}
Example #3
Source File: index.ts From node-express-typescript with MIT License | 6 votes |
app.use(function(req:Request, res: Response, next:NextFunction) {
if(!fs.existsSync(frontEndPath+req.path) && allRoutes.filter(r => req.path.startsWith(r)).length < 1){
console.log('redirect:',req.path)
res.sendFile(frontEndPath + 'index.html');
} else {
next()
}
});
Example #4
Source File: auth.ts From node-express-typescript with MIT License | 6 votes |
protected = (req: Request, res: Response, next: NextFunction) => {
const authHeader = req.header('Authorization');
if (authHeader) {
const token = authHeader.split(' ')[1];
const jwt: AuthObject = this.decode(token);
if (jwt) {
console.log(jwt)
req.user = jwt;
next();
}
}
if(typeof req.user === 'undefined'){
res.status(401).json({error: 'unauthorized'}).end();
}
}
Example #5
Source File: resolver.ts From node-express-typescript with MIT License | 6 votes |
update = async (req: Request, res: Response) => {
res.json(await this.model.update(req.body))
}
Example #6
Source File: resolver.ts From node-express-typescript with MIT License | 5 votes |
get = async (req: Request, res: Response) => {
const id = req.params.id || req.user.userId;
res.json(await this.model.get(id));
}
Example #7
Source File: resolver.ts From node-express-typescript with MIT License | 5 votes |
getAll = async (req: Request, res: Response) => {
res.json(await this.model.find());
}
Example #8
Source File: resolver.ts From node-express-typescript with MIT License | 5 votes |
create = async (req: Request, res: Response) => {
res.json(await this.model.create(req.body))
}