Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Express from 'express';
import GraphHTTP from 'express-graphql';
import Schema from './schema';
// Config
const APP_PORT = 3000;
// Start
const app = Express();
// GraphQL
app.use('/graphql', GraphHTTP({
schema: Schema,
pretty: true,
graphiql: true
}));
app.listen(APP_PORT, ()=> {
console.log(`App listening on port ${APP_PORT}`);
});
import TYPES from '../hooks-types'
import basicAuth from 'express-basic-auth'
import path from 'path'
import fs from 'fs'
import jsYaml from 'js-yaml'
import parseDomain from 'parse-domain'
import compression from 'compression'
import ssrConf from './config'
import {
isMultiSite,
siteFromReq,
useStaticsByHost,
readHtmlTemplate
} from './utils'
const app = express()
app.set('x-powered-by', false)
// Read public env vars from public-env.yml file and make them available for
// middlewares by adding them to app.locals
try {
const publicEnvFile = fs.readFileSync(
path.join(process.cwd(), 'public-env.yml'),
'utf8'
)
app.locals.publicEnvConfig = jsYaml.safeLoad(publicEnvFile)
} catch (err) {
app.locals.publicEnvConfig = {}
}
// Read early-flush config.
import Vue from 'vue';
const renderer = require('vue-server-renderer').createRenderer();
import { createVueApp } from './Main.vue.js';
// REACT
import React from 'react';
import { StaticRouter } from 'react-router-dom';
import { renderToString } from 'react-dom/server';
import App from './App.react';
// ELM
import elmStaticHtml from 'elm-static-html-lib';
require('./Main');
const assets = require(process.env.RAZZLE_ASSETS_MANIFEST);
const server = express();
server
.disable('x-powered-by')
.use(express.static(process.env.RAZZLE_PUBLIC_DIR))
.get('*', async (req, res) => {
// VUE
const context = { url: req.url };
const { app } = createVueApp(context);
const vueMarkup = await renderer.renderToString(app);
// REACT
const reactMarkup = renderToString(
);
import path from 'path';
import chalk from 'chalk';
import express from 'express';
import compression from 'compression';
import bodyParser from 'body-parser';
const config = require('../config');
const apiRoute = require('./api');
const jwtAuth = require('./jwt-auth');
const db = require('./db');
const app = express();
/******** Middleware *************************************/
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.set('X-Powered-By', 'AppSeed');
next();
});
app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
/******** API Calls **************************************/
function prepareTest(t, opts) {
const app = express();
const storage = new GridFsStorage(opts);
const upload = multer({storage});
t.context.storage = storage;
t.context.upload = upload;
t.context.app = app;
}
export function start(port: number = PORT): Promise {
let requestCount: number = 0;
const app = express();
app.use(jsonParser());
app.use((req, res, next) => {
requestCount++;
next();
});
app.get('/get', ({ headers }: express.Request, res: express.Response) => {
debug('Received GET request');
res.status(headers['x-status-code'] ? parseInt(headers['x-status-code'] as string, 10) : 200);
res.setHeader('x-test-server-header', 'foo');
res.send({ headers, method: 'GET', path: '/get' });
});
app.post('/post', ({ headers, body }: express.Request, res: express.Response) => {
debug('Received POST request');
protected runWebServer() {
this.initCron()
this.http = Express()
this.http.use('/', Express.static('vue/dist'))
this.http.use((req, res, next) => {
if (req.url.indexOf('/api') === -1) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate')
res.header('Expires', '-1')
res.header('Pragma', 'no-cache')
return res.send(fs.readFileSync('vue/dist/index.html').toString())
}
next()
})
this.http.use(Express.urlencoded())
this.http.use(Express.json())
this.http.listen(this.config.listen, () => console.log(`Listening on port ${this.config.listen}`))
this.initializeControllers()
}
* @description Routes config class
* @param Routes
*/
import Routes from './config/routes.conf.js';
/**
* @description IApplication config class
* @param Routes
*/
import ApplicationConfig from './config/app.conf.js';
/**
* @description Create application with Express Framework
* @param app
*/
const app = express();
/**
* @description Create application server
* @param server
*/
const server = http.createServer(app);
/**
* @description Configure Database
*/
DBConfig.init();
/**
* @description Configure Application
*/
ApplicationConfig.init(app);
import { ApolloServer } from "apollo-server-express";
import express from "express";
import cors from "cors";
import schema from "./graphql";
import { formatParams, getRepos } from "./common";
const port = parseInt(process.env.PORT || "2999", 10) || 2999;
const server = new ApolloServer({ schema, introspection: true });
const app = express();
app.use(cors());
server.applyMiddleware({ app, path: "/api/graphql", cors: true });
app.get("/api/repos", async (req, res) => {
const { language, time = 7 } = req.query;
const { params } = formatParams(language, time);
const repos = await getRepos(params);
return res.send({ items: repos });
});
app.listen(port, (err: Error) => {
if (err) throw err;