-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from zarathustra323/branding
Robots.txt + sitemap.xml; stitch graph schema; publisher context
- Loading branch information
Showing
20 changed files
with
782 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"verbose": true, | ||
"ignore": ["node_modules", ".next"], | ||
"watch": ["src/server/**/*", "server.js"], | ||
"watch": ["src/server/**/*.js", "server.js"], | ||
"ext": "js json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ fragment StoryViewFragment on Story { | |
id | ||
title | ||
teaser | ||
url | ||
publishedAt | ||
advertiser { | ||
id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
#import '../../fragments/story/view.graphql' | ||
|
||
query StoryPage($input: PublishedStoryInput!) { | ||
query StoryPage($input: PublishedStoryInput!, $publisherId: String) { | ||
publishedStory(input: $input) { | ||
...StoryViewFragment | ||
publisher(contextId: $publisherId) { | ||
id | ||
name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { isURL } = require('validator'); | ||
|
||
const { | ||
port, | ||
cleanEnv, | ||
makeValidator, | ||
} = require('envalid'); | ||
|
||
const url = makeValidator((v) => { | ||
const opts = { protocols: ['http', 'https'], require_tld: false, require_protocol: true }; | ||
if (isURL(v, opts)) return v; | ||
throw new Error('Expected a valid URL with http or https'); | ||
}); | ||
|
||
module.exports = cleanEnv(process.env, { | ||
PORT: port({ desc: 'The port that express will run on.', default: 3005 }), | ||
GRAPHQL_URI: url({ desc: 'The GraphQL URI for proxying/stitching API requests. Should follow the https://[account_key].[domain].[tld] structure in production.' }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { graphql } = require('graphql'); | ||
const createSchema = require('./schema'); | ||
|
||
module.exports = async (options = {}, resultKey) => { | ||
const schema = await createSchema(); | ||
return graphql({ ...options, schema }).then(res => (resultKey ? res.data[resultKey] : res.data)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { HttpLink } = require('apollo-link-http'); | ||
const fetch = require('isomorphic-unfetch'); | ||
const { | ||
makeRemoteExecutableSchema, | ||
introspectSchema, | ||
} = require('graphql-tools'); | ||
const env = require('../env'); | ||
|
||
const { GRAPHQL_URI } = env; | ||
|
||
const link = new HttpLink({ | ||
uri: `${GRAPHQL_URI}/graph`, | ||
fetch, | ||
}); | ||
|
||
let promise; | ||
module.exports = async () => { | ||
const build = async () => { | ||
const schema = await introspectSchema(link); | ||
return makeRemoteExecutableSchema({ | ||
schema, | ||
link, | ||
}); | ||
}; | ||
if (!promise) { | ||
// Prevents the introspection from happening more than once. | ||
// What happens, though, when the remote schema updates? | ||
// This would cache the schema and would require a reload of the app. | ||
promise = build(); | ||
} | ||
return promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const handlebars = require('handlebars'); | ||
const { readFileSync } = require('fs'); | ||
|
||
// Register custom helpers, etc here... | ||
|
||
const renderTemplate = (path, data) => { | ||
const source = readFileSync(`${__dirname}/templates/${path}`).toString(); | ||
const template = handlebars.compile(source); | ||
return template(data); | ||
}; | ||
|
||
module.exports = { handlebars, renderTemplate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const helmet = require('helmet'); | ||
const { Router } = require('express'); | ||
const { ApolloServer } = require('apollo-server-express'); | ||
const createSchema = require('../graph/schema'); | ||
|
||
const router = Router(); | ||
|
||
const create = async () => { | ||
const schema = await createSchema(); | ||
router.use(helmet.noCache()); | ||
const server = new ApolloServer({ schema }); | ||
server.applyMiddleware({ app: router, path: '/' }); | ||
}; | ||
|
||
create(); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
const proxy = require('http-proxy-middleware'); | ||
const index = require('./root'); | ||
const graph = require('./graph'); | ||
const story = require('./story'); | ||
|
||
const { ROOT_URI } = process.env; | ||
|
||
module.exports = (server, client) => { | ||
server.use('/', index(client)); | ||
server.use('/story', story(client)); | ||
server.use('/graph', proxy({ | ||
target: `${ROOT_URI}/graph`, | ||
changeOrigin: true, | ||
})); | ||
server.use('/graph', graph); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# www.robotstxt.org/ | ||
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 | ||
|
||
User-agent: * | ||
Disallow: /graph | ||
|
||
Sitemap: {{uri}}/sitemap.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> | ||
{{#each items as |item|}} | ||
<url> | ||
<loc>{{item.loc}}</loc> | ||
{{#if item.lastmod}}<lastmod>{{item.lastmod}}</lastmod>{{/if}} | ||
<changefreq>{{item.changefreq}}</changefreq> | ||
<priority>{{item.priority}}</priority> | ||
|
||
{{#if item.image.loc}} | ||
<image:image> | ||
<image:loc>{{item.image.loc}} | ||
{{#if item.image.caption}}<image:caption>{{item.image.caption}}</image:caption>{{/if}} | ||
</image:loc> | ||
</image:image> | ||
{{/if}} | ||
|
||
</url> | ||
{{/each}} | ||
</urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = fn => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next); |
Oops, something went wrong.