How to use the ejs.__express function in ejs

To help you get started, we’ve selected a few ejs 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 fengshi123 / express_project / app.js View on Github external
res.header('Content-Type', 'application/json;charset=utf-8');
  res.header('Content-Type', 'video/mp4');
  res.header('Content-Type', 'audio/mp3');
  if (mimeType[req.url.split('.').pop()]) {
    res.header('Content-Type', mimeType[req.url.split('.').pop()] + ';charset:UTF-8');
  }
  next();
});

app.post('*', bodyParser.urlencoded({ extended: true }),
  function (req, res, next) {
    next();
  });

// view engine setup
app.engine('html', ejs.__express);
app.set('view engine', 'html');
app.use('/public', function (req, res, next) {
  // 判断是否为音视频,注意移动版微信会带参数from=message
  const videoParamsIndex = req.url.indexOf('.mp4?');
  const audioParamsIndex = req.url.indexOf('.mp3?');
  let noParamsUrl = req.url;
  if (videoParamsIndex > -1 || audioParamsIndex > -1) {
    noParamsUrl = req.url.split('?').shift();
  }
  if (noParamsUrl.split('.').pop() === 'mp4') {
    res.header('Content-Type', 'video/mp4');
  } else if (noParamsUrl.split('.').pop() === 'mp3') {
    res.header('Content-Type', 'audio/mp3');
  } else {
    res.type('html');
  }
github chenhongdong / article / 爬虫研究 / crawl-jj / web / server.js View on Github external
app.use(session({
    resave: true,               // 每次都重新保存session
    saveUninitialized: true,    // 保存未初始化的session
    secret: 'crawl'             // 指定密钥
}));
// 传给header模板user
app.use((req, res, next) => {
    res.locals.user = req.session.user;
    next();
});


// 设置模板引擎
app.set('view engine', 'html');
app.set('views', resolve(__dirname, 'views'));
app.engine('html', require('ejs').__express);

// 首页路径
app.get('/', async (req, res) => {
    let tagId = req.query.tagId;
    // 查询所有标签的对象
    let tags = await query('SELECT * FROM tags');
    tagId = tagId || tags[0].id;     // 查询标签的id
    // 根据tagId去查找对应的文章列表
    let articles = await query('SELECT articles.* FROM article_tag INNER JOIN articles ON article_tag.article_id=articles.id WHERE article_tag.tag_id=?', [tagId]);
    res.render('index', {
        tags,
        articles
    });
});

// 详情页路由
github mancioshell / NEMTAB / server.js View on Github external
app.configure(function() {
    // set up our express application
    app.set('port', port);
    app.use(express.logger('dev')); // log every request to the console
    app.use(express.cookieParser()); // read cookies (needed for auth)
    app.use(express.bodyParser()); // get information from html forms
    app.set('view engine', 'html'); // set up html for templating
    app.engine('.html', require('ejs').__express);
    app.set('views', __dirname + '/views');
    app.use(express.static(path.join(__dirname, 'public')));
    //app.use(express.session({ secret: 'keyboard cat' }));// persistent login sessions
    app.use(express.methodOverride());
    app.use(express.json());
    app.use(express.urlencoded());
    //app.use(flash()); // use connect-flash for flash messages stored in session

    //passport configuration
    app.use(passport.initialize());
    //app.use(passport.session());// persistent login sessions
    //provagg
    app.use(app.router); //init routing

});
github bsspirit / nodejs-demo / app.js View on Github external
, http = require('http')
  , path = require('path')
  , ejs = require('ejs')
  , SessionStore = require("session-mongoose")(express);

var store = new SessionStore({
    url: "mongodb://localhost/session",
    interval: 120000 // expiration check worker run interval in millisec (default: 60000)
});

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.engine('.html', ejs.__express);
app.set('view engine', 'html');// app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser()); 
app.use(express.cookieSession({secret : 'blog.fens.me'}));
app.use(express.session({
  	secret : 'blog.fens.me',
    store: store,
    cookie: { maxAge: 900000 } // expire session in 15 min or 900 seconds
}));
app.use(function(req, res, next){
  res.locals.user = req.session.user;
  var err = req.session.error;
  delete req.session.error;
github ManfredHu / Books-Management-System / app / app.js View on Github external
var express = require('express'),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    expressSession = require('express-session')
    // ,cookieSession = require('cookie-session')
;

//开启一个服务器
var app = express();

//对服务器设置.html后缀文件需要经过EJS模板引擎编译
app.engine('.html', require('ejs').__express);

//对服务器设置views模板映射到/views目录下
app.set('views', __dirname + '/views');
app.set('view engine', 'html');

//全局定义express中间件
app.use(bodyParser.urlencoded({
        extended: true
    }))
    .use(bodyParser.json())
    .use(expressSession({
        secret: 'secret', //加密
        resave: false,
        saveUninitialized: true,
        cookie: {
            path: '/',
github openplacedatabase / www / app.js View on Github external
credentials_file: process.env.OPD_CRED_FILE ? process.env.OPD_CRED_FILE : path.join(__dirname,'.credentials.json')
}

// Load credentials file
if(fs.existsSync(app.locals.settings.credentials_file)) {
  app.locals.settings.creds = JSON.parse(fs.readFileSync(app.locals.settings.credentials_file));
} else {
  app.locals.settings.creds = {};
}

// Serve up static files in assets directory
app.use('/assets', express.static(__dirname + '/assets'));
app.use(express.favicon(__dirname + '/assets/img/favicon.ico'));

// Setup ejs as the template/layout engine
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');

// Use cookies
app.use(express.cookieParser());
app.use(require(__dirname + '/lib/options.js'));

// Make the request body available as text instead of a stream
app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));

/**
 * Routes
 */
fs.readdir(__dirname + '/routes', function(error, files){
  if(error){
github lincenying / mmf-blog-vue2-pwa-ssr / server.js View on Github external
} else {
    // In development: setup the dev server with watch and hot-reload,
    // and create a new renderer on bundle / index template update.
    readyPromise = require('./build/setup-dev-server')(app, (bundle, options) => {
        renderer = createRenderer(bundle, options)
    })
}

const serve = (path, cache) =>
    express.static(resolve(path), {
        maxAge: cache && isProd ? 1000 * 60 * 60 * 24 * 30 : 0
    })

// 引用 esj 模板引擎
app.set('views', path.join(__dirname, 'dist'))
app.engine('.html', require('ejs').__express)
app.set('view engine', 'ejs')

app.use(compression({ threshold: 0 }))

// 日志
app.use(logger('":method :url" :status :res[content-length] ":referrer" ":user-agent"'))
// body 解析中间件
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
// cookie 解析中间件
app.use(cookieParser())
// 设置 express 根目录

app.use(express.static(path.join(__dirname, 'dist')))
app.use('/static', serve('./dist/static', true))
app.use(favicon('./static/img/icons/favicon-32x32.png'))
github gregjopa / d3-server-side-demo / app.js View on Github external
var express = require('express');
var app = express();


app.engine('.html', require('ejs').__express);
app.set('views', __dirname);
app.set('view engine', 'html');


var fixtureData = require('./fixture_data.json');
app.locals.barChartHelper = require('./bar_chart_helper');


app.get('/', function(req, res) {
  res.render('index', { fixtureData: fixtureData });
});


app.listen(3000);
console.log('listening on port 3000');
github justJokee / vue-ssr-blog / front / server.js View on Github external
const bodyParser = require('body-parser')
const ueditor = require("ueditor")
const logger = require('morgan')
const route = require("./server/api")
const compression = require('compression')
const template = fs.readFileSync('./src/index.template.html', 'utf-8')
const isProd = process.env.NODE_ENV === 'production'
const server = express()
server.use(logger('dev'))//日志记录中间件,将请求信息打印在控制台
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({ extended: true }))
server.use(cookieParser())

//引入ejs模板引擎
server.set('views', path.join(__dirname, 'dist'))
server.engine('.html', require('ejs').__express)
server.set('view engine', 'ejs')
route(server)
function createRenderer (bundle, options) {
    return createBundleRenderer(bundle, Object.assign(options, {
        template: template,
        cache: LRU({
            max: 1000,
            maxAge: 1000 * 60 * 15
        }),
        basedir: resolve('./dist'),
        runInNewContext: false
    }))
}
let renderer
let readyPromise
if (isProd) {