Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import setupRouter from './router/router';
import setupCors from './libs/cors';
import siteConf from '../config/site';
const app = new Koa();
// Import and Set Nuxt.js options
let config = require('../nuxt.config.js');
config.dev = !(app.env === 'production');
const host = config.dev ? siteConf.dev.host : siteConf.prod.host;
let port = config.dev ? siteConf.dev.port : siteConf.prod.port;
// 正式环境下启用https
if (!config.dev) {
console.log('enable https');
app.use(enforceHttps());
// port = 80;
}
// Instantiate nuxt.js
const nuxt = new Nuxt(config);
// Build in development
if (config.dev) {
const builder = new Builder(nuxt);
builder.build().catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});
}
setupCors(app);
convert(
hotMiddleware(compile, {
log: console.log, // eslint-disable-line
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
})
)
);
app.use(logger());
app.use(mount('/emails', emails));
} else if (process.env.NODE_ENV === 'production') {
// Force redirect to HTTPS protocol unless explicitly disabled
if (process.env.FORCE_HTTPS !== 'false') {
app.use(
enforceHttps({
trustProtoHeader: true,
})
);
} else {
console.warn('Enforced https was disabled with FORCE_HTTPS env variable');
}
// trust header fields set by our proxy. eg X-Forwarded-For
app.proxy = true;
// catch errors in one place, automatically set status and response headers
onerror(app);
if (process.env.BUGSNAG_KEY) {
bugsnag.register(process.env.BUGSNAG_KEY, {
filters: ['authorization'],
const main = async () => {
const app = new Koa()
app.keys = [SESSION_SECRET_KEY]
const router = new Router()
setUpRouting(router)
DISABLE_SSL || app.use(enforceHttps({ trustProtoHeader: true }))
app.use(async (ctx, next) => {
try {
await next()
} catch (err) {
ctx.status = err.status || 500
ctx.app.emit('error', err, ctx)
ctx.redirect('/error')
}
})
app.use(
session(
{
maxAge: 1000 * 60 * 60 * 24 * 14, // 2 weeks
rolling: true,
console.log(err)
});
render(app, {
root: path.join(__dirname, 'view'),
layout: 'template',
viewExt: 'html',
cache: true,
debug: SYSTEM.DEBUG
});
// 生产环境启用https
let options = null;
if(IS_HTTPS == 'TRUE'){
// Force HTTPS on all page
app.use(enforceHttps())
options = {
key: fs.readFileSync(path.resolve(__dirname, './assets/cert/214545337340023.key')),
cert: fs.readFileSync(path.resolve(__dirname, './assets/cert/214545337340023.pem'))
}
}
app
.use(cookie())
.use(session(app))
.use(KoaBody({
multipart: true,
formidable: {
uploadDir: path.join(__dirname, '/upload')
}
}))
import etag from 'koa-etag'
import koa from 'koa'
import request from 'request'
import passport from 'koa-passport'
export const app = new koa()
const logger = morgan('combined')
import enforceHttps from 'koa-sslify'
const config = require('../config.json')
if(config.https){
if(config.heroku){
app.use(enforceHttps({
trustProtoHeader: true
}))
} else {
app.use(enforceHttps())
}
}
// app.use(favicon(__dirname+'../dist/icon.ico'))
// app.use(rt())
// app.use(logger)
app.use(compress({
filter: () => true,
flush: require('zlib').Z_SYNC_FLUSH
}))
app.use(async (ctx,next) => {
await next()
await send(ctx, ctx.path, { root: __dirname + '/../dist' })
})
// app.use(conditional())
// app.use(etag())
});
//404
back.get('*', async(ctx,next)=>{
let datas = {
title:'404页面',
}
await ctx.render('404',{
datas:datas
});
})
let options=null;
if(IS_HTTPS === 'TRUE'){
// Force HTTPS on all page
app.use(enforceHttps())
options= {
key: fs.readFileSync(path.resolve(__dirname, './assets/cert/214586773670023.key')),
cert: fs.readFileSync(path.resolve(__dirname, './assets/cert/214586773670023.pem'))
}
}
app
.use(cookie())
.use(session(app))
.use(KoaBody({
multipart: true,
text:true,
formidable: {
uploadDir: path.join(__dirname, '/upload')
}
}))
port: 1234,
}));
new Koa().use(sslify({
hostname: 'my-host',
}));
new Koa().use(sslify({
temporary: false,
}));
new Koa().use(sslify({
redirectMethods: ['GET'],
}));
new Koa().use(sslify({
skipDefaultPort: false,
}));
new Koa().use(sslify({
ignoreUrl: true,
}));
import sslify, { xForwardedProtoResolver, azureResolver, customProtoHeaderResolver, forwardedResolver } from 'koa-sslify';
new Koa().use(sslify());
new Koa().use(sslify({}));
new Koa().use(sslify({
resolver: xForwardedProtoResolver,
}));
new Koa().use(sslify({
resolver: azureResolver,
}));
new Koa().use(sslify({
resolver: customProtoHeaderResolver('x-protocol'),
}));
new Koa().use(sslify({
resolver: forwardedResolver,
}));
new Koa().use(sslify({
disallowStatus: 405,
}));
new Koa().use(sslify({
port: 1234,
}));
new Koa().use(sslify({
hostname: 'my-host',