我想使用Nginx作为我的网络服务器和我自己的Dropwiward REST API,使用Vue.js构建单页面应用程序.此外,我使用Axios来调用我的REST请求.
我的nginx配置看起来像
server {
listen 80;
server_name localhost;
location / {
root path/to/vue.js/Project;
index index.html index.htm;
include /etc/nginx/mime.types;
}
location /api/ {
rewrite ^/api^/ /$1 break;
proxy_pass http://localhost:8080/;
}
}
Run Code Online (Sandbox Code Playgroud)
目前我可以打电话给我localhost/api/path/to/rescource
从后端获取信息.
我用HTML和javascript(vue.js)构建前端,到目前为止已经工作了.但是,当我想构建单个页面应用程序时,大多数教程都提到了node.js. 我怎样才能使用Nginx?
如果这是一个愚蠢的问题,我很抱歉,我对 Vue 还是很陌生。我创建了一个 Vue(使用命令vue init webpack <project-name>
)项目并开始添加组件,其中第一个是导航栏。但是后来我注意到 body 标签margin: 8px
默认情况下会导致我的页面和浏览器之间始终有一个 8px 的空白区域。我一生都无法弄清楚如何摆脱这个边距,我尝试使用以下 css:
* { margin: 0 !important; }
Run Code Online (Sandbox Code Playgroud)
和
body { margin: 0 !important; }
Run Code Online (Sandbox Code Playgroud)
我试图将它直接添加到根 index.html 的样式标签和我所有组件的样式标签中,但根本无法摆脱它。
我正在尝试编写一个函数,该函数将在用户创建时发送欢迎电子邮件。我跟着这个教程,它说可以访问新创建的用户的displayName
with user.displayName
,尽管它一直null
为我返回。我意识到发生这种情况的可能原因(如果我错了,请纠正我)是注册和设置用户的 displayName 发生在客户端的两个单独步骤中,因此onCreate
触发user.displayName
时自然为空。这是我的客户端代码,供参考:
fb.auth().createUserWithEmailAndPassword(payload.email, payload.password).then(user => {
return user.user.updateProfile({ displayName: payload.name, });
}).catch(/* ... */);
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是一个在user.updateProfile
. 我已经查看了该auth.user().onOperation
函数(在此处找到),但是当我尝试将此函数部署到Error: Functions did not deploy properly.
firebase 时,出现错误(有用,ikr),我想这与该onOperation
函数有关private
(如果我,请纠正我)我错了)。
有什么办法可以做我想做的事吗?如果是这样,如何?或者,有没有办法设置displayName
on createUserWithEmailAndPassword
,以便我可以继续使用该onCreate
功能?
这是我当前的onCreate
代码:
exports.sendWelcomeEmail = functions.auth.user().onCreate(user => {
console.log('name:', user.displayName);
});
Run Code Online (Sandbox Code Playgroud)
这是我对该onOperation
功能的尝试:
exports.sendWelcomeEmail = functions.auth.user().onOperation(user => {
console.log('user:', user);
}, 'updateProfile');
Run Code Online (Sandbox Code Playgroud) javascript firebase firebase-authentication google-cloud-functions
当我尝试部署新创建的 Firebase PubSub 函数时,出现错误Error: Failed to create scheduler job projects/workouts-uat/locations/europe-west1/jobs/firebase-schedule-dailyTasks-eur3: HTTP Error: 400, Schedule or time zone is invalid.
我的函数声明如下:
exports.dailyTasks = functions
.region('europe-west2')
.pubsub
.schedule('every 24 hours 00:00')
.timeZone('Africa/Johannesburg')
.onRun(...);
Run Code Online (Sandbox Code Playgroud)
根据我的研究,我发现使用的区域应该与项目设置中找到的区域相同,在我的例子中是eur3 (europe-west)
. 我所有现有的onCall
函数都使用europe-west2
这就是为什么我首先尝试使用它,但在找到我的项目设置区域后我更新为.region('eur3')
和.region('europe-west')
,但错误仍然存在。那么如何成功部署这个功能呢?
我在谷歌搜索错误时遇到的另一个提示是,必须创建“Google App Engine (GAE) 应用程序”才能使 pubsub 函数正常工作,但我假设这会在函数部署时自动发生,对吗?否则如何创造它?我对 GCP 的经验为零。
我正在尝试使用jquery和firebase创建一个注册系统,而我遇到问题的问题是不知道'对firebase的调用'返回了什么.让我在我的代码中向您展示:
HTML(通过删除不相关的代码简化):
<div id="registerForm">
<input type="text" id="userEmail" placeholder="Email">
<input type="password" id="userPass" placeholder="Password">
<button type="button" id="register">Register</button>
</div>
Run Code Online (Sandbox Code Playgroud)
JQuery(再次,只显示与Firebase和注册相关的代码):
<script src=" /* Jquery url */ "></script>
<script src=" /* Firebase url */ "></script>
<script>
// Initialize Firebase
var config = {
apiKey: "*my api key*",
authDomain: "*myProject*.firebaseapp.com",
databaseURL: "https://*myProject*.firebaseio.com",
storageBucket: "*myProject*.appspot.com",
};
firebase.initializeApp(config);
</script>
<script>
$('#register').click(function() {
var email = $('#userEmail');
var pass = $('#userPass');
if(email.val() && pass.val()){
// this is where I stop knowing how all this firebase stuff …
Run Code Online (Sandbox Code Playgroud) 我对Vue很陌生,我正在尝试用它来创建我的第一个应用程序(我已经完成了整个教程,所以它不像我对它一样全新).我来自Java/Grails背景,所以这个新的"面向前端的webapps"仍然让我很困惑.我正在使用Vue 2和webpack.
我遇到的问题是当app初始化时会运行方法,这会在App.vue组件中创建数据(我假设它是根组件,这是正确的吗?)然后在子组件中访问这些数据.所以我特别想要做的是在'创建'生命周期钩子中我想检查用户是否登录然后我想相应地更新我的导航栏(如果没有则显示登录按钮,否则显示例如,用户的名字.
我甚至还没弄清楚我到底是如何确定用户是否已登录到目前为止我只是尝试在App.vue组件中创建虚拟数据然后在子组件中访问它.我研究过的每个地方都说我应该使用一个事件总线,但(我认为)这对我不起作用(如果我错了,请纠正我)因为我能找到的唯一例子是用户调用所有$ emit函数事件(如按钮点击),我希望它始终可以在任何地方全局访问(和变异)数据.
所以我会试着向你展示一些我想到的代码:
App.vue:
...stuff...
data() {
return {
authToken = '',
userdetails = {},
loggedIn = false
}
},
created: function() {
// check browser storage for authToken
if(authToken) {
// call rest service (through Vue Resource) to Grails backend that I set up
// beforehand and set this.userdetails to the data that gets returned
if(this.userdetails) {
this.loggedIn = true;
}
}
}
...stuff...
Run Code Online (Sandbox Code Playgroud)
Home.vue:
<template>
<div class="home">
<nav-bar></nav-bar>
</div>
</template>
...stuff
Run Code Online (Sandbox Code Playgroud)
NavBar.vue:
<template>
<div class="navBar"> …
Run Code Online (Sandbox Code Playgroud) 我在 SO 和其他地方查看了这个问题的一堆答案,但我能找到的只是人们只想找到最高 id、最大 dateCreated 或最新数据库条目的情况,但我想做的是检索创建的最新对象也符合另一个条件。我的域类具有以下属性:id
、number
、company
、type
和dateCreated
。content
该company
属性只能设置为“OYG”或“BAW”,并且该number
属性是一个自动递增的 int。number
我想要做的是检索属性设置为“OYG”或“BAW”的最高记录company
。
这是一个例子:
+----------------------------------------------------------+
| id | number | company | type | dateCreated | content |
+----------------------------------------------------------+
| 1 | 0 | OYG | TsAndCs | 15/09/2016 | stuff |
| 2 | 0 | BAW | TsAndCs | 15/09/2016 | stuff |
| 3 | 1 | OYG | TsAndCs | 16/09/2016 | …
Run Code Online (Sandbox Code Playgroud) 我的Intellij Debugger窗口丢失了,我找不到任何关于如何取回它的资源,最接近我认为我的问题是缺少控制台窗口,但这没有帮助.所以我希望有人能帮助我找回它.
这张照片显示了一个正常的Intellij IDE(我从我的朋友那里得到的),它显示了我缺少的标签(红色)和此标签通常显示的区域(黄色).
这张照片显示我的IDE缺少调试器窗口.
我还打开了Intellij的帮助对话框,声称当你的代码遇到断点时窗口会出现,但这对我来说也没有.
我有一个包含多个join
s 的 SQL 查询 (Postgres),但我无法将其转换为单个 Knex.js 语句。这是 SQL 查询:
SELECT
User.id, User.name, User.email,
Role.name AS r_name,
UserPofile.id AS p_id, UserPofile.date_of_birth AS p_dob,
AuthToken.id AS at_id, AuthToken.token AS at_token, AuthToken.platform AS at_platform
FROM public."user" User
LEFT JOIN public."user_role" UserRole ON User.id = UserRole.user_id
LEFT JOIN public."role" Role ON UserRole.role_id = Role.id
LEFT JOIN public."application" Application ON UserProfile.app_id = Application.id
LEFT JOIN public."user_profile" UserProfile ON User.id = UserProfile.user_id
LEFT JOIN public."auth_token" AuthToken ON User.id = AuthToken.user_id
WHERE
User.email LIKE 'some@email.com' …
Run Code Online (Sandbox Code Playgroud) 我的问题很简单:我想编译一个 Handlebars 视图然后不渲染它 - 相反,我想使用编译的 HTML 服务器端。在研究这个问题时,这是我能找到的最接近我的问题,但除非我误解了,否则他们在这个问题中所做的一切都是在服务器端创建一个 HTML 字符串并用数据填充它。这是不够的,因为我不想创建任何 HTML 字符串,我真的想将我的 HTML 存储在.hbs
文件,像往常一样,然后编译一个视图(即发送它我的变量),然后而不是将它显示给用户(无论如何这不可能,因为它只是一个 API 服务器),我想让编译的 HTML 到将它发送到 Mailgun(但我想将它发送到 Mailgun 的事实超出了范围,答案最好只告诉我如何编译视图并能够(例如)console.log()
HTML)。
我正在使用 Node v9.8.0
套餐:
如果我需要提供任何其他信息,请告诉我,我没有包含我尝试过的任何示例代码的原因是我实际上不知道该尝试什么。我所尝试的只是let emailHtml = res.render('email/contactReceipt.hbs', { name:req.body.name })
在我的路线内,但这给了我错误Cannot set headers after they are sent to the client
。
旁注:我对 Node.js 还很陌生,它不是我正常堆栈的一部分。我注意到其他人使用包 'express-handlebars' 甚至只是 'handlebars' 所以如果我使用的('hbs')实际上与 Handlebars 没有任何关系,或者如果我不能完成我正在尝试做的事情,让我知道。