Skip to content

Instantly share code, notes, and snippets.

@xvaara
Last active November 8, 2020 19:28
Show Gist options
  • Save xvaara/d344c90fdb914e3c3ad8024560db7f79 to your computer and use it in GitHub Desktop.
Save xvaara/d344c90fdb914e3c3ad8024560db7f79 to your computer and use it in GitHub Desktop.
const ROOT_URL = process.env.ROOT_URL;
const httpEndpoint = `${ROOT_URL}/graphql`;
export default (context) => {
// console.log("apollo", context);
return {
httpEndpoint: httpEndpoint,
headers: { "CSRF-Token": context.$config.token }
};
};
export default {
mode: "universal",
modules: ["@nuxtjs/apollo"],
apollo: {
clientConfigs: {
default: "~/plugins/apollo.js"
}
},
// or create hook here
// hooks: {
// "vue-renderer": {
// ssr: {
// context(ctx) {
// ctx.nuxt.config.token = ctx.req.csrfToken()
// // console.log("vue-renderer:ssr:context called", arguments);
// }
// },
// }
// }
};
import { Express } from "express";
// @ts-ignore
import { Builder, Nuxt } from "nuxt";
const isDev = process.env.NODE_ENV === "development";
// We instantiate Nuxt.js with the options
// @ts-ignore
import config from "../../../nuxt-client/nuxt.config.js";
config.dev = isDev;
config.hooks = {
...config.hooks,
"vue-renderer": {
ssr: {
context(ctx: any) {
ctx.nuxt.config.token = ctx.req.csrfToken()
// console.log("vue-renderer:ssr:context called", ctx);
}
},
},
}
const nuxt = new Nuxt(config);
export default async function installSSR(app: Express) {
await nuxt.ready();
// No build in production
if (isDev) {
const builder = new Builder(nuxt);
builder.build();
}
app.use(nuxt.render);
console.log("Nuxt!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment