Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function(app /* , wildcatConfig*/) {
console.info("Initializing server-only api...");
const sampleRoute = route.get(
"/react-wildcat-server-only-example",
function*() {
this.body = "Hello from the server world!";
}
);
app.use(sampleRoute);
};
const app = koa()
const paperpress = new Paperpress({
baseDirectory: 'static',
uriPrefix: '/blog',
pathBuilder: function (item, collectionName) {
if (collectionName === 'articles') {
return `post/${item.slug}`
} else if (collectionName === 'pages') {
return `/page/${item.slug}`
}
}
})
paperpress.load()
app.use(route.get('/', list))
app.use(route.get('/feed', feed))
app.use(route.get('/page/:slug', page))
app.use(route.get('/post/:slug', show))
/** Route Definitions **/
// Post listing //
function * list (ctx) {
this.body = yield paperpress.getCollection('articles')
console.log('[koa-paperpress] /')
}
// Show post :slug //
function * show (slug) {
const articles = paperpress.getCollection('articles')
const article = _.findWhere(articles, {type: 'articles', slug: slug})
const staticRoute = require('koa-static');
const parse = require('co-body');
// const render = require('./lib/render');
const views = require('co-views');
const path = require('path');
const app = module.exports = Koa();
//Temp Database
let db = [];
/**
* Setup middleware
*/
app.use(staticRoute('./static'));
app.use(route.get('/', list));
app.use(route.get('/posts/new', add));
app.use(route.get('/post/:id', show));
app.use(route.post('/post', create));
/**
* Setup route generators
*/
function* list() {
console.log('DATABASE:', db)
this.body = yield view('list', {posts: db});
}
function* add() {
this.body = yield view('new');
}
const useServeStatic = (app) => {
const servePublic = serve(path.join(__dirname, '../public'));
// In production we want to serve our JS from a file on the filesystem.
// Otherwise we want to proxy the webpack development server.
const serveClient = process.env.NODE_ENV === 'production' ?
serve(path.join(__dirname, 'dist/client')) :
proxy({ target: 'http://localhost:8888', pathRewrite: { '^/static': '' } })
app.use(route.get('/', servePublic));
app.use(route.get('/static', serveClient));
return app;
}
import proxy from 'koa-proxy';
import _debug from 'debug';
import webpackConfig from '../config/webpack.config';
import config from '../config';
import logs from './logs.js';
import webpackDevMiddleware from './middleware/webpack-dev';
import webpackHMRMiddleware from './middleware/webpack-hmr';
const debug = _debug('app:server');
const paths = config.utils_paths;
const app = new Koa();
const _ = require('koa-route');
app.use(_.get('/chatlogs', logs.getAllLogs));
app.use(_.get('/deletelogs', logs.deleteAllLogs));
app.use(_.get('/tone/:conversationID', logs.tone));
// Enable koa-proxy if it has been enabled in the config.
if (config.proxy && config.proxy.enabled) {
app.use(convert(proxy(config.proxy.options)));
}
// This rewrites all routes requests to the root /index.html file
// (ignoring file requests). If you want to implement isomorphic
// rendering, you'll want to remove this middleware.
app.use(convert(historyApiFallback({
verbose: false,
})));
var views = require('co-views');
var parse = require('co-body');
var koa = require('../..');
var app = koa();
// "database"
var posts = [];
// middleware
app.use(logger());
// route middleware
app.use(route.get('/', list));
app.use(route.get('/post/new', add));
app.use(route.get('/post/:id', show));
app.use(route.post('/post', create));
// route definitions
/**
* Post listing.
*/
function *list() {
this.body = yield render('list', { posts: posts });
}
/**
* Show creation form.
// Load config
this.config = await ConfigManager.getConfiguration();
this.port = this.port || this.config.port;
this.host = this.host || this.config.host;
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
this.renderer = new Renderer(browser, this.config);
this.app.use(koaLogger());
this.app.use(koaCompress());
this.app.use(bodyParser());
this.app.use(route.get('/', async (ctx: Koa.Context) => {
await koaSend(
ctx, 'index.html', { root: path.resolve(__dirname, '../src') });
}));
this.app.use(
route.get('/_ah/health', (ctx: Koa.Context) => ctx.body = 'OK'));
// Optionally enable cache for rendering requests.
if (this.config.cache === 'datastore') {
const { DatastoreCache } = await import('./datastore-cache');
this.app.use(new DatastoreCache().middleware());
} else if (this.config.cache === 'memory') {
const { MemoryCache } = await import('./memory-cache');
this.app.use(new MemoryCache().middleware());
}
this.app.use(
if (fse.pathExistsSync(CONFIG_PATH)) {
this.config = Object.assign(this.config, await fse.readJson(CONFIG_PATH));
}
const browser = await initPuppeteer();
browser.setMaxListeners(1024);
this.browser = browser;
this.renderer = new Renderer(this.browser);
this.crawlerScheduler = new CrawlerScheduler(browser);
this.app.use(koaCompress());
this.app.use(bodyParser());
this.app.use(
route.get('/', async (ctx: Koa.Context) => {
await koaSend(ctx, 'index.html', {
root: path.resolve(__dirname, '../src/public')
});
})
);
this.app.use(
route.get('/_ah/health', (ctx: Koa.Context) => (ctx.body = 'OK'))
);
// Optionally enable cache for rendering requests.
if (this.config.useCache) {
this.app.use(this.datastoreCache.middleware());
}
this.app.use(
route.get('/render/:url(.*)', this.handleRenderRequest.bind(this))
module.exports = async function (port = 3000) {
const app = new Koa()
app.use(router.get('/shot', pageshot))
app.use(serve('public'))
app.listen(port, () => {
console.log(`Pageshot server running on ${port}`)
})
app.on('error', err => {
console.error('ERR_APP:', err)
})
return app
}
exports.init = function (app) {
app.use(route.post('/login', login));
app.use(route.get('/login/facebook', facebookLogin));
app.use(route.get('/login/facebook/callback', facebookCallback));
app.use(route.get('/login/google', googleLogin));
app.use(route.get('/login/google/callback', googleCallback));
};