Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyichen committed Apr 22, 2019
0 parents commit f34ee5d
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc
@@ -0,0 +1,6 @@
{
"presets": [
"next/babel",
"@zeit/next-typescript/babel"
]
}
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules/
.next/
package-lock.json
2 changes: 2 additions & 0 deletions next.config.js
@@ -0,0 +1,2 @@
const withTs = require('@zeit/next-typescript');
module.exports = withTs();
15 changes: 15 additions & 0 deletions nodemon.json
@@ -0,0 +1,15 @@
{
"ignore": [
"**/*.test.ts",
"**/*.spec.ts",
".git",
"node_modules",
".next"
],
"watch": [
"server",
"types"
],
"exec": "npm run dev",
"ext": "ts"
}
47 changes: 47 additions & 0 deletions package.json
@@ -0,0 +1,47 @@
{
"name": "ydb",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"tsc": "tsc",
"dev": "ts-node --files ./server/index.ts",
"nodemon": "./node_modules/nodemon/bin/nodemon.js",
"lint:ts": "tslint -c tslint.json 'src/**/*.ts*'",
"pretty": "prettier --write client/**/*.ts* server/**/*.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/express-graphql": "^0.6.2",
"@types/graphql": "^14.2.0",
"@types/morgan": "^1.7.35",
"@zeit/next-typescript": "^1.1.1",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
"express-router-async": "^0.3.0",
"graphql": "^14.2.1",
"morgan": "^1.9.1",
"next": "^8.1.0",
"nodemon": "^1.18.11",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"ts-node": "^8.1.0",
"typescript": "^3.4.4"
},
"devDependencies": {
"@types/express": "^4.16.1",
"@types/next": "^8.0.3",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"prettier": "^1.17.0",
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0"
},
"lint-staged": {
"*.ts*": [
"npm run pretty",
"git add"
]
}
}
3 changes: 3 additions & 0 deletions pages/_error.tsx
@@ -0,0 +1,3 @@
import * as React from 'react';

export default () => <h1>o no error</h1>
3 changes: 3 additions & 0 deletions pages/home.tsx
@@ -0,0 +1,3 @@
import * as React from 'react';

export default () => <h1>i home!</h1>
3 changes: 3 additions & 0 deletions pages/index.tsx
@@ -0,0 +1,3 @@
import * as React from 'react';

export default () => <h1>hi</h1>
16 changes: 16 additions & 0 deletions server/graph/index.ts
@@ -0,0 +1,16 @@
import { GraphQLSchema, GraphQLObjectType } from 'graphql';

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueries',
description: 'Top level queries',
fields: () => ({}),
}),
mutation: new GraphQLObjectType({
name: 'RootMutations',
description: 'Top level mutations',
fields: () => ({}),
}),
});

export default schema;
24 changes: 24 additions & 0 deletions server/index.ts
@@ -0,0 +1,24 @@
import * as express from 'express';
import * as morgan from 'morgan';
import nextjs from './lib/next';
import PagesRouter from './routers/pages';
import GraphqlRouter from './routers/graphql';

const app: express.Application = express();

nextjs.nextApp.prepare().then(() => {
const port = process.env.SERVER_PORT || 8080;

app.use(morgan(':method :url :status'));

app.use(PagesRouter);
app.use(GraphqlRouter);

app.get('*', (req, res) => {
nextjs.handle(req, res);
});

app.listen(port, function() {
console.log(`started on port ${port}`);
});
});
15 changes: 15 additions & 0 deletions server/lib/next.ts
@@ -0,0 +1,15 @@
import * as express from 'express';
import * as next from "next";

const isDev = process.env.NODE_ENV !== 'production';

const nextApp = next({ dev: isDev });
const handle = nextApp.getRequestHandler();

const nextjs = {
nextApp,
handle,
render: (req: express.Request, res: express.Response, page: string) => nextApp.render(req, res, page),
};

export default nextjs;
17 changes: 17 additions & 0 deletions server/routers/graphql.ts
@@ -0,0 +1,17 @@
import * as express from 'express';
import * as graphqlHTTP from 'express-graphql';
import schema from '../graph';

const router = express.Router();

router.get('/graphql', graphqlHTTP({
schema,
graphiql: true,
}))

router.post('/graphql', graphqlHTTP({
schema,
graphiql: false,
}))

export default router;
15 changes: 15 additions & 0 deletions server/routers/pages.ts
@@ -0,0 +1,15 @@
import * as express from 'express';
import * as asyncRouter from 'express-router-async';
import nextjs from '../lib/next';

const router = asyncRouter();

router.get('/', (req: express.Request, res: express.Response) => {
nextjs.render(req, res, '/');
});

router.getAsync('/home', async (req: express.Request, res: express.Response) => {
nextjs.render(req, res, '/home');
});

export default router;
25 changes: 25 additions & 0 deletions tsconfig.json
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"lib": [
"dom",
"es2017"
],
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"removeComments": false,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es6"
},
"include": [
"./types/**/*"
]
}
15 changes: 15 additions & 0 deletions tslint.json
@@ -0,0 +1,15 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"quotemark": [
true,
"single"
]
},
"rulesDirectory": []
}
14 changes: 14 additions & 0 deletions types/expressRouterAsync.d.ts
@@ -0,0 +1,14 @@
declare namespace Express {
interface IRoute {
getAsync: express.IRouterMatcher<this>;
postAsync: express.IRouterMatcher<this>;
}
}

declare module 'express-router-async' {
import * as express from 'express';

const router = express.IRouter;

export = router: express.IRouter;
};

0 comments on commit f34ee5d

Please sign in to comment.