标签: keystonejs

如何允许特定服务器访问我的API?

我正在使用node.js、express和mongodb编写一个API,它将在另一台服务器中使用。我只希望该服务器(或将来的更多服务器)能够访问我的 API。我怎样才能做到这一点?

api node.js server keystonejs

4
推荐指数
1
解决办法
5420
查看次数

无法使用 MongoDB 配置 Keystone 6

我正在尝试使用 MongoDB 作为数据库来设置 Keystone。运行后keystone-next,该命令出错并显示以下错误消息:Error: Invalid db configuration. Please specify db.provider as either "sqlite" or "postgresql" at getDBProvider

他们的文档中没有明确说明db.provider使用 MongoDB 作为数据库时要传递哪些值。

以下是 的内容keystone.ts

import { config, createSchema } from '@keystone-next/keystone/schema'
import 'dotenv/config'

const databaseUrl =
  process.env.DATABASE_URL || 'mongodb://localhost/keystone-project'

const sessionConfig = {
  maxAge: 60 * 60 * 24 * 90,
  secret: process.env.COOKIE_SECRET || 'keystone-project-secret'
}

export default config({
  server: {
    cors: {
      origin: [process.env.FRONTEND_URL],
      credentials: true
    }
  },
  db: {
    provider: 'mongoose',
    url: …
Run Code Online (Sandbox Code Playgroud)

mongodb keystonejs keystonejs6

4
推荐指数
1
解决办法
2885
查看次数

在Jade中调用每个函数

我正在尝试在Jade模板中实现Google地图.使用KeystoneJS作为CMS,我有一些"配置文件"(基本上是人们的地址)我想要添加到地图作为标记.

block js
  script.
        var map;
        function initialize() {
            var mapOptions = {
              center: new google.maps.LatLng(51.0360272, 3.7359072),
              zoom: 8
            };
            map = new google.maps.Map(document.getElementById("map-canvas"),
                mapOptions);

        }

        google.maps.event.addDomListener(window, 'load', initialize);

block content
   .container
       script(src='https://maps.googleapis.com/maps/api/js?key=<GOOGLE_API_KEY>&sensor=false')

     if data.profiles
        each profile in data.profiles
            #{new google.maps.Marker({position: new google.maps.LatLng(profile.address.geo[1], profile.address.geo[0]), map: map, title: profile.name.full})}

    div(id="map-canvas", style="width:100%; height:700px;")
Run Code Online (Sandbox Code Playgroud)

地图显示正确,但是当我添加"每个"代码块时,我收到错误"无法读取未定义的属性'贴图'".

如何在Jade中添加一段在'each'上执行的js代码?

javascript google-maps-api-3 node.js keystonejs pug

3
推荐指数
1
解决办法
4359
查看次数

Keystone.js Admin UI - 表单中没有字段

我创建了这样一个模型:

var keystone = require('keystone'),
    Types = keystone.Field.Types;

var Page = new keystone.List('Page', {
    autokey: { path: 'slug', from: 'menuTitle', unique: true },
    map: { name: 'menuTitle' },
});

Page.add({
    keyword: { type: Types.Key, required: true, initial: false },
    slug: { type: Types.Key, required: true, initial: false },
    type: { type: Types.Select, options: 'textpage, projects, services, contacts, homepage', default: 'textpage' },
    menuTitle: { type: String, required: true, initial: false },
    pageTitle: { type: String },
    pageContent: { type: Types.Html, wysiwyg: …
Run Code Online (Sandbox Code Playgroud)

node.js keystonejs

3
推荐指数
1
解决办法
1447
查看次数

KeystoneJS - 创建新项目会引发重复键错误

我见过一些与此相关的类似问题,但没有找到答案.

我正在尝试在我的Keystone项目中创建一个类似于帖子的图库,其中将有一个图库列表,其中包含一组选定图像的图库:

var keystone = require('keystone'),
    Types = keystone.Field.Types;

/**
 * Gallery Model
 * =============
 */

var Gallery = new keystone.List('Gallery', {
    map: { name: 'name' },
    autokey: { path: 'slug', from: 'name', unique: true }
});

Gallery.add({
    name: { type: String, required: true},
    published: {type: Types.Select, options: 'yes, no', default: 'no', index: true},
    publishedDate: { type: Types.Date, index: true, dependsOn: { published: 'yes' } },
    description: { type: String },
    heroImage : { type: Types.Relationship, ref: 'Image' },
    images …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb keystonejs

3
推荐指数
1
解决办法
1015
查看次数

Keystonejs List对象的未定义'model'属性

我创建了一个包含非常简单的列表(国家/地区)的示例,并根据此处的说明创建了api路由:https://gist.github.com/JedWatson/9741171

server.js:

app.get('/api/countries', keystone.middleware.api, routes.api.countries.list);

路线/ API/countries.js:

import keystone from 'keystone';

export function list(req, res) {
  keystone.List('Country').model.find((err, items) => {
    if (err) return res.apiError('database error', err);

    res.apiResponse({
      countries: items
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

我收到错误Cannot read property 'find' of undefined,List对象存在但它没有model属性.有人知道为什么吗?keystone管理UI按预期工作,数据库中有多个对象.

keystonejs

3
推荐指数
1
解决办法
372
查看次数

提高 mongo 查询性能

我正在使用名为 Keystone 的基于节点的 CMS 系统,该系统使用 MongoDB 作为数据存储,从而对数据和访问提供相当自由的控制。我有一个非常复杂的模型,称为Family,它有大约 250 个字段、一堆关系和十几个方法。我的网站上有一个表单,允许用户输入所需的信息来创建新的家庭记录,但是处理时间很长(在本地主机上为 12 秒,在我的 Heroku 实例上超过 30 秒)。我遇到的问题是 Heroku 对于运行超过 30 秒的任何进程都会发出应用程序错误,这意味着我需要优化我的查询。除一项功能外,所有处理都发生得非常快。下面是有问题的函数:

const Family = keystone.list( 'Family' );

exports.getNextRegistrationNumber = ( req, res, done ) => {

    console.time('get registration number');

    const locals = res.locals;

    Family.model.find()
        .select( 'registrationNumber' )
        .exec()
        .then( families => {

            // get an array of registration numbers
            const registrationNumbers = families.map( family => family.get( 'registrationNumber' ) );

            // get the largest registration number
            locals.newRegistrationNumber = Math.max( …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js keystonejs

3
推荐指数
1
解决办法
862
查看次数

如何从 Apollo Server 端点获取完整的 GraphQL 模式?

我正在使用 Apollo Server 编写 GraphQL 和 REST 服务之间的 GraphQL 接口。该接口将为 Apollo 客户端前端提供单个 GraphQL 端点。

目前唯一的服务是 KeystoneJS 应用程序,它通过(据我所知)Apollo Server 提供 GraphQL 端点。为了暂时简单起见,我从 KeystoneJS 服务器 GraphQL Playground 下载 GraphQL 架构,并将其用作我的界面的 GraphQL 架构(在删除 Keystone 生成且 Apollo Server 无法理解的定义之后)。

我想自动化这个过程——也就是说,以某种方式“抓取”KeystoneJS/Apollo Server 生成的 GraphQL 模式,就像我从 GraphQL Playground 下载它一样。有没有办法从端点做到这一点?(我不想触及 KeystoneJS 内部结构,只需通过端点访问模式)

graphql keystonejs apollo-server graphql-schema

3
推荐指数
1
解决办法
4737
查看次数

Handlebars Scope问题:无法从嵌入式`each`访问模板变量

我试图弄清楚为什么我无法从each我的手柄模板中的嵌入语句中访问我的模板变量(在我的keystone项目中呈现).我在StackOverflow上已经阅读了许多类似问题的问题,但没有一个解决了我的特定用例.

我有一个简单的数据对象,传递给Handlebars模板,看起来像[粗略]这样:

{ 
   rootPath: '../../../', 
   navigation: { all: { 'a': { sublinks: [Object] }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

为什么rootPath模板变量完美打印{{#each navigation.all}},但内部无法访问{{#each sublinks}}

这是我的Handlebars模板:

<!-- rootPath prints fine here -->
Here is your rootPath variable: {{rootPath}}

{{#each navigation.all}}

    <!-- rootPath prints fine here -->
    top-level rootPath: {{../rootPath}}

    {{#if sublinks}}

            {{#each sublinks}}

                <!-- WHY WON'T ROOTPATH PRINT HERE?? -->
                <!-- Obviously, I am trying the three possible scope paths -->
                sub-level rootPath attempt 1: {{../../rootPath}} …
Run Code Online (Sandbox Code Playgroud)

html javascript templates handlebars.js keystonejs

2
推荐指数
1
解决办法
747
查看次数

Keystone JS CORS

好的,所以我对 Keystone JS 还很陌生,我决定将其用作项目的 API 后端。

我已经完成了所有 API 端点/路由,并且它们在我的浏览器中运行良好,但是当尝试远程获取数据时,我不断收到相同的错误:XMLHttpRequest 无法加载http://localhost:3000/keystone/api/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost '。

我对 CORS 并不陌生,并尝试通过将以下内容添加到我的 keystone.js 和 routes/index.js 来启用它

基石.js:

keystone.set('cors allow origin', true);
keystone.set('cors allow methods', true);
keystone.set('cors allow headers', true);
Run Code Online (Sandbox Code Playgroud)

路线/ index.js:

// Setup Route Bindings
exports = module.exports = function (app) {
    app.all('/api/*', keystone.middleware.cors);
    app.options('/api*', function(req, res) { res.send(200); });

    // Views
    app.get('/', routes.views.index);

    // API
    // Lists
    ...
Run Code Online (Sandbox Code Playgroud)

现在我已经尝试通过查看大量文档来寻找解决方案,但根据我的发现,这应该足以让 CORS 与 Keystone 一起工作。

除此之外,我还将在我的 Angular JS 1.x 前端展示我的 Keystone 服务,让您看看我想要实现的目标。

keystone.service.js:

(function() …
Run Code Online (Sandbox Code Playgroud)

node.js cors keystonejs

2
推荐指数
1
解决办法
1727
查看次数