我有这个代码:
"use strict";
import browserSync from "browser-sync";
import httpProxy from "http-proxy";
let proxy = httpProxy.createProxyServer({});
Run Code Online (Sandbox Code Playgroud)
我通过npm 安装babel-core并babel-cli全局安装.关键是当我尝试在终端上使用它编译时:
babel proxy.js --out-file proxified.js
Run Code Online (Sandbox Code Playgroud)
输出文件被复制而不是编译(我的意思是,它与源文件相同).
我在这里错过了什么?
我正在开发基于地理定位的应用程序,因此必须首先获取位置,甚至在执行应用程序的其余部分之前也是如此。那么,如何以同步方式转换此模块????
var geolocation = (function() {
'use strict';
var geoposition;
var options = {
maximumAge: 1000,
timeout: 15000,
enableHighAccuracy: false
};
function _onSuccess (position) {
console.log('DEVICE POSITION');
console.log('LAT: ' + position.coords.latitude + ' - LON: ' + position.coords.longitude);
geoposition = position
};
function _onError (error) {
console.log(error)
};
function _getLocation () {
navigator.geolocation.getCurrentPosition(
_onSuccess,
_onError,
options
);
}
return {
location: _getLocation
}
}());
Run Code Online (Sandbox Code Playgroud)
非常感谢!
我正在使用节点代理服务器将 API 请求转发到另一台服务器。这工作正常,但不适用于文件上传。显然,标头设置正确,但不知何故,图像未处理到“最终”服务器。我应该怎么办?。谢谢!
function pipeRequest(client_req, client_res, method) {
var options = {
hostname: HOSTNAME,
port: PORT,
path: client_req.url,
method: method
};
var proxy = http.request(options, function (res) {
res.pipe(client_res, {
end: true
});
});
if(client_req.url === "/ops/blong/image/upload"){
console.log(client_req.headers['content-type']);
}
client_req.pipe(proxy, {
end: true
});
}
function onRequest(client_req, client_res) {
var my_path = url.parse(client_req.url).pathname,
full_path = path.join(process.cwd(), my_path);
//Forward API calls
if (client_req.method === 'POST') {
pipeRequest(client_req, client_res, 'POST');
//Return local files for static content
} else {
filesys.exists(full_path, function (exists) …Run Code Online (Sandbox Code Playgroud)