Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('cleanup-files');
return new AV.Query(AV.File).limit(999).destroyAll({ useMasterKey: true }).then(function() {
console.log('Files deleted');
}, function(error) {
console.error('cleanup files error: ' + error.message);
});
});
// handle uncaught exceptions so the application cannot crash
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
console.trace();
});
// leanengine health checker
app.use(AV.express());
// start the server
var PORT = process.env.LEANCLOUD_APP_PORT || process.env.PORT || 8080;
app.listen(PORT, function () {
console.log('Listening at http://localhost:' + PORT);
});
const express = require('express')
const AV = require('leanengine')
const axios = require('axios')
const path = require('path')
AV.init({
appId: process.env.LEANCLOUD_APP_ID || 'Cct4URhkJo6VKYACsR3MklFt-gzGzoHsz',
appKey: process.env.LEANCLOUD_APP_KEY || 'BeJzllYAryhOzoNX0piav8tw',
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY || 'U5jcAlilltDr1vJmyfwIqC2D'
})
const app = express()
app.use(AV.express())
app.use(express.static(path.resolve(__dirname, './dist')))
const V2EX_BASE_URL = 'https://www.v2ex.com/api'
// v2ex topic info
app.get('/news/v2ex/topics/show.json?', function (req, response) {
let url = ''
if (req.query.id) {
const id = req.query.id
url = `${V2EX_BASE_URL}/topics/show.json?id=${id}`
axios.get(url).then(res => {
response.send(res.data[0])
})
} else if (req.query['node_name']) {
const contentType = req.query['node_name']
url = `${V2EX_BASE_URL}/topics/show.json?node_name=${contentType}`
Lean.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
})
// 如果不希望使用 masterKey 权限,可以删除
Lean.Cloud.useMasterKey()
// Init Express App
const app = express()
// Middlewares and Routes
app.use(express.static('dist'))
app.use(timeout('15s'))
app.use(Lean.express())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(uncaughtException)
app.all('/api/*', CORS)
// APIs setup
app.use('/api', API)
// Error handlers
app.use(errorHandler)
app.use(notFound)
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
const PORT = parseInt(process.env.LEANCLOUD_APP_PORT || 3000)
// babel 编译
require('babel-core/register');
// 各个模块
const apiRouter = require('./api-router');
const tool = require('./tool');
const config = require('./config');
// 设置 view 引擎
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'ejs');
app.use(express.static('public'));
// 使用 LeanEngine 中间件
app.use(AV.express());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
// 未处理异常捕获 middleware
app.use((req, res, next) => {
let d = domain.create();
d.add(req);
d.add(res);
d.on('error', (err) => {
console.error('uncaughtException url=%s, msg=%s', req.url, err.stack || err.message || err);
if (!res.finished) {
res.statusCode = 500;
res.setHeader('content-type', 'application/json; charset=UTF-8');
// 启用 WebSocket 支持,如不需要可去除
require('express-ws')(app)
// 设置模板路径和默认引擎
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
// 设置静态内容路径
app.use('/public', express.static('public'))
// 设置默认超时时间
app.use(timeout('15s'))
// 加载云引擎中间件
app.use(AV.express())
// 跳转 HTTP 至 HTTPS
app.enable('trust proxy')
app.use(AV.Cloud.HttpsRedirect())
// 加载 cookieSession 以支持 AV.User 的会话状态
app.use(AV.Cloud.CookieSession({ secret: 'randomString', maxAge: 3600000, fetchUser: true }))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/', require('./routes/markdown'))
app.use('/cookie-session', require('./routes/cookie-session'))
app.use('/render-ejs', require('./routes/render-ejs'))
app.use('/websocket', require('./routes/websocket'))
var express = require('express');
var AV = require('leanengine');
const path = require('path')
AV.init({
appId: process.env.LEANCLOUD_APP_ID || 'fHlQK5K3zQdGFO0h4jPg7Azk-gzGzoHsz',
appKey: process.env.LEANCLOUD_APP_KEY || 'Tpz60WuMnnBGJGh3hr6os321',
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY || 'gf5hWN1qI2XreblTMLNB80TP'
});
var app = express();
app.use(AV.express());
app.use(express.static(path.resolve(__dirname, './dist')))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './dist/index.html'))
})
app.listen(process.env.LEANCLOUD_APP_PORT);
console.log('Server started')
import app from './express-app'
import AV from 'leanengine'
AV.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
})
app.use(AV.express())
export default app
const express = require('express');
const AV = require('leanengine');
const app = express();
app.use(AV.express());
app.use(require('./middleware')());
module.exports = app;
const getToken = require('./libs/common');
getToken();
//创建菜单
const createMenu = require('./libs/wxCustomeMenu');
createMenu();
//引入路由
const weixin = require('./routes/weixin');
const auth = require('./routes/auth');
const userinfo = require('./routes/userinfo');
//app配置
const app = express();
app.use(AV.express());
app.set('views', path.join(__dirname, '../views'));
//解析xml
app.use(bodyParser.xml({
limit: '1MB',
xmlParseOptions: {
normalize: true,
normalizeTags: true,
explicitArray: false
}
}));
//启用nunjucks模板
app.engine('html', nunjucks.render);
app.set('view engine', 'html');