Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
const PgIdToRowIdInflectorPlugin = require('./plugins/PgIdToRowIdInflectorPlugin');
const PgNonNullRelationsPlugin = require('@graphile-contrib/pg-non-null/relations');
// constants
const postgresUser = process.env.POSTGRES_USER;
const postgresPassword = process.env.POSTGRES_PASSWORD;
const postgresPort = process.env.POSTGRES_PORT;
const postgresDb = process.env.POSTGRES_DB;
const noAuth = !!process.env.NO_AUTH;
console.log(`Starting PostGraphile${noAuth ? ' in no-auth mode' : ''}...\n`);
http
.createServer(
postgraphile(
`postgres://${postgresUser}:${postgresPassword}@postgres:${postgresPort}/${postgresDb}`,
'public', // introspected schema
{
classicIds: true,
dynamicJson: true,
setofFunctionsContainNulls: false,
ignoreRBAC: false,
pgDefaultRole: noAuth ? 'viewer' : 'anonymous',
disableDefaultMutations: true,
disableQueryLog: false,
jwtSecret: process.env.POSTGRAPHILE_JWT_SECRET,
graphiql: true,
watchPg: true,
jwtPgTypeIdentifier: 'private.jwt_token',
graphileBuildOptions: {
pgStrictFunctions: true,
const express = require('express')
const { postgraphile } = require('postgraphile')
const { Pool } = require('pg')
const pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
})
const app = express()
const postgraphileInstance = postgraphile(pool, process.env.DB_SCHEMA, {
// Dev, debug, test
graphiql: process.env.NODE_ENV === 'development',
enhanceGraphiql: process.env.NODE_ENV === 'development',
// JWT Authentication
jwtSecret: process.env.JWT_SECRET,
defaultRole: process.env.JWT_ROLE,
jwtPgTypeIdentifier: process.env.JWT_TOKEN,
// Postgraphile recommended config
setofFunctionsContainNulls: true,
// If none of your RETURNS SETOF compound_type functions
// mix NULLs with the results
// then you may set this true
// to reduce the nullables in the GraphQL schema.
ignoreRBAC: false,
const { postgraphile } = require("postgraphile");
const PostGraphileUploadFieldPlugin = require("postgraphile-plugin-upload-field");
const { graphqlUploadExpress } = require("graphql-upload");
const app = express();
const UPLOAD_DIR_NAME = "uploads";
// Serve uploads as static resources
app.use(`/${UPLOAD_DIR_NAME}`, express.static(path.resolve(UPLOAD_DIR_NAME)));
// Attach multipart request handling middleware
app.use(graphqlUploadExpress());
app.use(
postgraphile("postgres://localhost:5432/upload_example", "public", {
graphiql: true,
enableCors: true,
appendPlugins: [PostGraphileUploadFieldPlugin],
graphileBuildOptions: {
uploadFieldDefinitions: [
{
match: ({ column }) => column === "header_image_file",
resolve: resolveUpload,
},
],
},
})
);
app.listen(5000, () => {
// eslint-disable-next-line
module.exports = app => {
const httpServer = app.get("httpServer");
const authPgPool = app.get("authPgPool");
/*
* If we're using subscriptions, they may want access to sessions/etc. Make
* sure any websocketMiddlewares are installed before this point. Note that
* socket middlewares must always call `next()`, otherwise you're going to
* have some issues.
*/
const websocketMiddlewares = app.get("websocketMiddlewares");
// Install the PostGraphile middleware
const middleware = postgraphile(
authPgPool,
"app_public",
postgraphileOptions({
websocketMiddlewares,
})
);
app.use(middleware);
if (enhanceHttpServerWithSubscriptions) {
enhanceHttpServerWithSubscriptions(httpServer, middleware);
}
};
const dbInfo = require('./database')();
require('./swagger')(app, cors);
app.use('/api/docs', cors(), express.static('./node_modules/swagger-ui-dist'));
app.use(swStats.getMiddleware({
swaggerSpec: require('../swagger'),
apdexThreshold: 250,
authentication: true,
onAuthenticate: (req, username, password) => {
return username.toLowerCase() == process.env.USERNAME.toLowerCase() && password == process.env.PASSWORD
}
}));
app.use(postgraphile(dbInfo.connectionString, 'public', {
disableDefaultMutations: true,
graphiql: true
}));
let corsConfig = cors(corsOptions);
require('../app/coach/coach.route')(app, dbInfo.db, corsConfig);
require('../app/game/game.route')(app, dbInfo.db, corsConfig, speedLimiter);
require('../app/play/play.route')(app, dbInfo.db, corsConfig);
require('../app/team/team.route')(app, dbInfo.db, corsConfig);
require('../app/venue/venue.route')(app, dbInfo.db, corsConfig);
require('../app/rankings/rankings.route')(app, dbInfo.db, corsConfig);
require('../app/lines/lines.route')(app, dbInfo.db, corsConfig);
require('../app/recruiting/recruiting.route')(app, dbInfo.db, corsConfig);
require('../app/ratings/ratings.route')(app, dbInfo.db, corsConfig);
require('../app/ppa/ppa.routes')(app, dbInfo.db, corsConfig);
require('../app/stats/stats.routes')(app, dbInfo.db, corsConfig);
function installPostgraphile(app) {
app.use(postgraphile(db, schemas, postgraphileOptions))
}