How to use the express.Router function in express

To help you get started, we’ve selected a few express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blade254353074 / nodejs-blog / routes / index.js View on Github external
// 入口文件
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Article = require('../models/article').Article,
    Links = require('../models/links').Links;

var hbs = require('hbs');
var _global = {};

mongoose.connect('mongodb://localhost/express-test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.on('open', function(callback) {
    console.log('数据库连接成功');

    // 读取博客站点配置
    var Config = require('../models/config').Config;
    var meta_dynamic = '',
github revov / uci-gui / server / api / import.js View on Github external
module.exports = function(passport, socketioService) {
    var router = express.Router();

    router.post('/',
        ensureLoggedIn,
        function(req, res) {
            var user = req.user.toObject();
            if(req.body && req.body.pgnContent) {
                var chess = new Chess();

                // load the pgn
                if( chess.load_pgn(req.body.pgnContent) ) {
                    var pgnHeader = chess.header(),
                        newGame = new Game({
                                        pgn: req.body.pgnContent,
                                        uploadedByUserId: user._id,
                                        white: pgnHeader.White,
                                        whiteElo: pgnHeader.WhiteElo,
github MilkZoft / MuuCMS / src / backend / app / auth / auth.controller.js View on Github external
// Dependencies
import express from 'express';
import passport from 'passport';
import FacebookStrategy from 'passport-facebook';
import TwitterStrategy from 'passport-twitter';

// Configuration
import { $baseUrl, $social } from '@configuration';

// Express Router
const Router = express.Router();

// Facebook
const fbOptions = {
  clientID: $social().facebook.clientId,
  clientSecret: $social().facebook.clientSecret,
  callbackURL: `${$baseUrl()}${$social().facebook.callbackUrl}`,
  profileFields: $social().facebook.profileFields
};

const twOptions = {
  consumerKey: $social().twitter.consumerKey,
  consumerSecret: $social().twitter.consumerSecret,
  callbackURL: $social().twitter.callbackUrl,
  userProfileURL: $social().twitter.userProfileURL,
  includeEmail: true
};
github rajaraodv / draftjs-examples / app.js View on Github external
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var router = express.Router();



var app = express();

app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');


// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Request-Headers", "*");
  res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
github IBM / Train-Custom-Speech-Model / src / routes / pages.ts View on Github external
public constructor() {
    this.router = Router();
    this.init();
  }
  private init() {
github broidHQ / integrations / broid-viber / src / core / Adapter.ts View on Github external
constructor(obj: IAdapterOptions) {
    this.serviceID = obj && obj.serviceID || uuid.v4();
    this.logLevel = obj && obj.logLevel || 'info';
    this.token = obj && obj.token || null;
    this.username = obj && obj.username || null;
    this.avatar = obj && obj.avatar || '';
    this.webhookURL = obj && obj.webhookURL.replace(/\/?$/, '/') || '';

    this.storeUsers = new Map();
    this.parser = new Parser(this.serviceName(), this.serviceID, this.logLevel);
    this.logger = new Logger('adapter', this.logLevel);

    this.router = Router();
    if (obj.http) {
      this.webhookServer = new WebHookServer(obj.http, this.router, this.logLevel);
    }
  }
github Mailtrain-org / mailtrain / routes / users.js View on Github external
'use strict';

let passport = require('../lib/passport');
let express = require('express');
let router = new express.Router();
let users = require('../lib/models/users');
let fields = require('../lib/models/fields');
let settings = require('../lib/models/settings');
let _ = require('../lib/translate')._;

router.get('/logout', (req, res) => passport.logout(req, res));

router.post('/login', passport.parseForm, (req, res, next) => passport.login(req, res, next));
router.get('/login', (req, res) => {
    res.render('users/login', {
        next: req.query.next
    });
});

router.get('/forgot', passport.csrfProtection, (req, res) => {
    res.render('users/forgot', {
github bleenco / abstruse / src / api / routes / repositories.ts View on Github external
import * as express from 'express';
import { decodeToken } from '../security';
import * as dbRepository from '../db/repository';
import { LogMessageType, logger } from '../logger';
import { getBitBucketAccessToken } from '../utils';
import { checkRepositoryAccess, Repository, checkConfigPresence, getRemoteParsedConfig } from '../config';

export const repositoriesRouter = express.Router();

class CheckRepoConfig {
  constructor(
    public readPermissions: boolean = false,
    public includesConfig: boolean = false,
    public canParseConfig: boolean = false
  ) { }
}

repositoriesRouter.get('/', (req: express.Request, res: express.Response) => {
  const token = req.headers.authorization || '';
  const keyword = req.query.keyword || '';

  return decodeToken(token)
    .then(data => {
      if (!data) {
github upframe / api / routes / search.ts View on Github external
import * as express from 'express'

import { Services } from '../service'
import { APIrequest } from '../types'

const router: express.Router = express.Router()

function setRouters(app: express.Application): void {
  const services: Services = app.get('services')

  router.get('/quick', (req: APIrequest , res: express.Response) => {
    services.search.quick(req, res)
  })

  router.get('/full', (req: APIrequest , res: express.Response) => {
    services.search.full(req, res)
  })

  router.get('/tags', (req: APIrequest , res: express.Response) => {
    services.search.tags(req, res)
  })
}