Correct way to connect to websocket using Kotlin/JS - kotlin

I've got a Kotlin/JS project (version 1.6.21) and I'm trying to connect to a Websocket backend, both when running locally and in production.
(UPDATE I also get the same error with Kotlin/JS 1.7.0)
If I hardcode the websocket URL
val ws = WebSocket("ws://localhost:12080/ws")
it works, but obviously that isn't suitable for multiple environments.
I've followed another answer and created a helper function to take the window.location.href (http://localhost:3000) and transform it to ws://localhost:3000/ws.
import kotlinx.browser.window
val websocketServerUrl: String
get() = window.location.href
.replace("http://", "ws://")
.replace("https://", "wss://") +
"ws"
I can see that this works correctly.
However, when I develop locally the websocket server is running on a different port: http://localhost:12080. As I understand the solution to this is to use 'Webpack Dev Server' to create a proxy. I've done this in my Gradle settings.
// build.gradle.kts
kotlin {
js(IR) {
browser {
runTask {
outputFileName = "main.bundle.js"
sourceMaps = false
devServer = KotlinWebpackConfig.DevServer(
open = false,
port = 3000,
proxy = mutableMapOf(
"/ws" to mapOf(
"target" to "http://localhost:12080",
"secure" to false,
"ws" to true,
"changeOrigin" to true,
),
),
static = mutableListOf("$buildDir/processedResources/js/main")
)
}
}
binaries.executable()
}
}
However I this doesn't work. In the browser log I see an error
WebSocket connection to 'ws://localhost:3000/ws' failed: Invalid frame header
WebSocketClient # WebSocketClient.js:18
initSocket # socket.js:21
eval # socket.js:40
And in the network tab I can see the 'ws' connection repeatedly fails
{"type":"hot"} 14 19:08:56.913
{"type":"liveReload"} 21 19:08:56.913
{"type":"overlay","data":true} 30 19:08:56.913
{"type":"hash","data":"9f9f3c947008c06acba0"} 45 19:08:56.913
{"type":"ok"} 13 19:08:56.913
Invalid frame header N/A 19:08:56.915
In the application log for the frontend I can see a repeated error
<i> [webpack-dev-server] [HPM] Upgrading to WebSocket
<e> [webpack-dev-server] [HPM] WebSocket error: Error: read ECONNRESET
<e> at TCP.onStreamRead (node:internal/stream_base_commons:220:20) {
<e> errno: -4077,
<e> code: 'ECONNRESET',
<e> syscall: 'read'
<e> }
package.json
This is the package.json that Kotlin/JS generates
{
"name": "my-project",
"version": "0.0.1",
"main": "my-project.js",
"types": "my-project.d.ts",
"devDependencies": {
"webpack": "5.69.1",
"webpack-cli": "4.10.0",
"format-util": "1.0.5",
"webpack-dev-server": "4.7.4",
"source-map-loader": "3.0.1"
},
"dependencies": {},
"peerDependencies": {},
"optionalDependencies": {},
"bundledDependencies": []
}
What's the correct way to set up a websocket connection?

Related

How to set vite.config.js base public path?

I'm trying to set a base url for both my dev and prod environments, but vitejs configs are not resolved.
According to vitejs , you can set the base public path when served in development or production, in your config options.
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root.
The issue is that my application requests don't go through 'http://localhost:8080/', but are still appended to the default serving port http://localhost:3000/.
My current configs are bellow:
// vite.config.js
export default {
base: 'http://localhost:8080/'
}
// packages.json
{
"name": "vue3ui",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
...,
"vue": "^3.0.11"
},
"devDependencies": {
"#vue/compiler-sfc": "^3.0.11",
"vite": "^1.0.0-rc.13"
}
}
Not totally clear to me but I will try to give you an answer to achieve what you want.
I'm trying to set a base url for both my dev and prod environments
Edit: I read again you question, and I think you are looking for the point C on this answer.
Changes should be made in vite.config.js
A) You are looking to change the running port from 3000 to 8080, adjust server.port
server: {
port: '8080'
}
B) But if you are looking to run on localhost:3000 and forward requests to localhost:8080 then you have to adjust server.proxy
server: {
proxy: {
'/': {
target: 'http://localhost:8080/'
},
'/admin': {
target: 'http://localhost:8081/'
}
}
}
example:
'/': will proxy all requests to localhost:8080
'/admin': will proxy only requests that have as endpoint /admin to http://localhost:8081
C) Changing base path depending on dev or prod environment
.env file :
// .env
// Running locally
APP_ENV=local
// you change port of local/dev here to :8000
// do not forget to adjust `server.port`
ASSET_URL=http://localhost:3000
// Running production build
APP_ENV=production
ASSET_URL=https://your-prod-asset-domain.com
vite.config.js:
const ASSET_URL = process.env.ASSET_URL || '';
export default {
base: `${ASSET_URL}/dist/`,
[...]
}
If it's not what you are looking for, please be more precise and I will edit my answer.
For more information, head to the official doc at https://vitejs.dev/config/#server-options
I think I understand what TC wants to solve.
He has 1 build for dev and prod envs.
But it depends on envs, he has a different base path.
Answer:
https://vitejs.dev/guide/build.html#advanced-base-options
At the moment it is an experimental feature
experimental: {
renderBuiltUrl(filename: string, { hostType }: { hostType: 'js' | 'css' | 'html' }) {
if (['js', 'css'].includes(hostType)) {
return { runtime: `window.__getFile(${JSON.stringify(filename)})` }
} else {
return { relative: true }
}
}
}
and create global function
window.__getFile = function(file){
if (window.location.host.includes('dev')) {
return `http://cdn.dev/${file}`
}
return `http://cdn.prod/${file}`
}
P.s. Sorry. I can't find any example with port

How to connect socket from VueJs with Sails js built in socket with sails.io.js in vue js?

I am trying to connect VueJs with Sails js over socket connection through Sails.io.js package but got not success till now.
I have taken VuejS starter template and sails js starter template to make this whole thing work.
My Frontend packages contains:
"sails.io.js": "^1.2.1",
"socket.io": "^3.1.0",
"socket.io-client": "^3.1.0",
"vue": "^2.6.11"
My Backend packages contains:
"#sailshq/connect-redis": "^3.2.1",
"#sailshq/lodash": "^3.10.3",
"#sailshq/socket.io-redis": "^5.2.0",
"grunt": "1.0.4",
"nodemon": "^2.0.7",
"sails": "^1.3.1",
"sails-hook-grunt": "^4.0.0",
"sails-hook-orm": "^2.1.1",
"sails-hook-sockets": "^2.0.0",
"socket.io": "^3.1.0"
On vuejs, my code is,
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<script>
var io = require('sails.io.js')( require('socket.io-client') );
io.sails.autoConnect = false;
io.sails.useCORSRouteToGetCookie = false
io.sails.url = 'http://localhost:1337';
export default {
name: 'Home',
components: {},
mounted() {
setTimeout(() => {
var socket0 = io.sails.connect();
}, 2000)
}
};
</script>
So I am trying to connect it after 2 seconds after vue component is mounted.
But every time i am getting one same error that is,
WebSocket connection to
'ws://localhost:1337/engine.io/?EIO=4&transport=websocket' failed:
Connection closed before receiving a handshake response
Then i tried changing io.sails.url = 'http://localhost:1337' to io.sails.url = 'ws://localhost:1337' with
but then it started showing error that is (incase of io.sails.useCORSRouteToGetCookie = true),
GET ws://localhost:1337/__getcookie net::ERR_DISALLOWED_URL_SCHEME
but then it started showing error that is (incase of io.sails.useCORSRouteToGetCookie = false),
WebSocket connection to 'ws://localhost:1337/engine.io/?EIO=4&transport=websocket' failed: Connection closed before receiving a handshake response
In sails js my setting for socket in config/sockets.js file is,
module.exports.sockets = {
transports: [ 'websocket' ],
};
I have gone through so many links and documentation of sails js, but no success till now.
After this i tried to connect socket with other available packages. those are,
"socket.io": "^3.1.0",
"socket.io-client": "^3.1.0",
"vue-socket.io-extended": "^4.0.6",
While using above packages,
My Vue js code is,
<script>
import Vue from 'vue';
import Axios from 'axios'
import VueSocketIOExt from 'vue-socket.io-extended';
import { io } from 'socket.io-client';
var socket = io('http://localhost:1337', { transports: ["websocket"] } );
Vue.use(VueSocketIOExt, socket);
export default {
sockets: {
connect() {
console.log('socket connected')
},
disconnect() {
console.log('socket disconnected')
},
foo(data) {
console.log('this method was fired by the socket server. eg: io.emit("customEmit", data): ')
console.log('data');
console.log(data);
}
},
name: 'Home',
components: {},
mounted () {
this.checkHello()
},
methods: {
checkHello () {
Axios.get('http://localhost:1337/api/testhello')
.then((response) => {
console.log('response');
console.log(response);
}).catch((error) => {
console.log('error');
console.log(error);
})
}
}
};
</script>
I have created on route with /api/testhello on sails js controller,
whose code is,
module.exports = {
testHello: function(req, res) {
// req.socket is undefind here
console.log('Hello Called')
let socketClientObj = sails.io.sockets.clients();
console.log('socketClientObj.server.eio.clients');
console.log(socketClientObj.server.eio.clientsCount);
sails.io.sockets.emit('foo', { thisIs: 'thisMessage'});
return res.status(200).json({
anyData: 'we want to send back'
});
}
}
With this, I am getting output on console of sails,
Hello Called
socketClientObj.server.eio.clients
1
But with this, My vuejs is connected with sails js and i am getting that one client is connected through the socket but i dont know how to get the connected user socket id or how to get the Socket instance.
with above what i am seeking is:
how to make room with approach of not using sails.io.js at frontend but using sails default build in socket functionality ?
how to connect particular user to that room because i am not getting Socket id of user who requested the URL in this approach of not using sails.io.js?
How to configure Redis Pub sub for cluster mode in sails js in case of above approch of not using sail.io.js in vue js?
Thanks in advance.
After battling with the
WebSocket connection to 'ws://localhost:1337/engine.io/?EIO=4&transport=websocket' failed: Connection closed before receiving a handshake response
error for the longest time digging around everywhere and taking the same steps you did,
what solved my problem eventually was:
npm remove vue-socket.io-extended (if installed)
npm remove socket.io-js
npm install socket.io-js#^2.4.0
Seems that sails.js adapter doesn't support socket.io-js#3.0.0 yet,
connection is working with version socket.io-js version 1 and 2 only, 2.4.0 is the latest.

Highly confusing express.Router() issue

I have a large application build with NestJS that I deploy using the serverless framework. I have been doing this for some time and everything has been great. A couple of days ago I had to update to Nestjs 7 and I have been experiencing a lot of issues bootstrapping my application when it is deployed to aws. After going through countless frustrating attempts to resolve the issue it appears it's actually nothing to do with the Nestjs/serverless bootstrapping process at all and apollo-server-express was unable to access the express router - failing with the error:
express_1.default.Router is not a function
Finally I realised that when I import express directly and try and access express.Router() I have the same issue. So I made a very simple test:
lambda.ts:
import { Context, Handler } from "aws-lambda";
import express from "express";
export const handler: Handler = async (event: any, context: Context) => {
console.log("Import express:", express);
console.log("Test express app: ", express());
console.log("Test router:", express.Router());
/* express.Router() ->
ERROR TypeError: express_1.default.Router is not a function at
/var/task/dist/lambda.js:19:51 at Generator.next (<anonymous>) at
/var/task/dist/lambda.js:8:71 at new Promise (<anonymous>) at
__awaiter (/var/task/dist/lambda.js:4:12) at exports.handler (/var/task/dist/lambda.js:16:39) at
Runtime.handler (/var/task/serverless_sdk/index.js:9:131872) at
Runtime.handleOnce (/var/runtime/Runtime.js:66:25)
*/
};
This fails with the error in the comment as previously stated. Here are the other files:
serverless.yml:
service: xxxxx
app: xxxx
tenant: xxxxx
plugins:
- serverless-pseudo-parameters
- serverless-prune-plugin
- serverless-deployment-bucket
provider:
name: aws
runtime: nodejs12.x
region: eu-west-1
stage: dev
timeout: 29
memorySize: 3008
deploymentBucket:
name: ${self:service}-${self:custom.currentStage}-deployment-bucket
serverSideEncryption: AES256
custom: ${file(./serverless-common.yml):custom}
package:
include:
- ./dist/**
exclude:
- node_modules/aws-sdk/**
functions:
index:
handler: ./dist/lambda.handler
name: bm-${self:custom.currentStage}-express-test
events:
- http:
path: "/{proxy+}"
method: POST
package.json:
{
"name": "#xxx/XXXXXX",
"version": "0.1.13",
"dependencies": {
"express": "4.17.1"
},
"devDependencies": {
"serverless-deployment-bucket": "1.1.1",
"serverless-prune-plugin": "1.4.2",
"serverless-pseudo-parameters": "2.5.0",
"ts-node": "^8.7.0",
"tsconfig-paths": "^3.7.0",
"tslint": "5.12.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.8.3"
}
}
tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"#root/*": ["src/*"]
},
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "dist",
"esModuleInterop": true
},
"include": ["*"],
"exclude": ["**/node_modules/**/*", "dist"]
}
I would like to highlight that this code only fails once deployed to lambda. It runs fine locally which would make indicate that perhaps something was up with the packaging process but the zip file contains the correct code and dependencies.
I have been working on this problem for ages before narrowing it down to this. If anybody is able to shed any light on the above that would be greatly appreciated as it's obviously blocking me.
Many thanks
UPDATE:
OK it appears that if I:
import Router from 'express/lib/router'
then I get a router instance. This is the same instance the express index should export.
So I am close but this feels wrong, I haven't changed anything, I feel like I have some kind of incorrect module configuration or something.
So why can't I do express.Router(). Any ideas would be greatly appreciated.
UPDATE:
In the end I patched apollo-server-express so that it gets the router instance from lib/router and then everything works as expected.
I obviously do not want to do this so I really need to work out what's causing this.
Patched ApolloServer.js: https://gist.github.com/TreeMan360/8dc8373ffebe2b24ff51df42090fcb52
UPDATE:
Another related issue has developed in that the headers are returned as part of the response body e.g:
HTTP/1.1200OKX-Powered-By: ExpressAccess-Control-Allow-Origin: *Content-Type: application/json;charset=utf-8Content-Length: 155ETag: W/"9b-mbrRmusN4ADjvBFA5aFJNLyRMHs"Date: Sat,
04Apr202014: 35: 09GMTConnection: keep-alive{
"data": {
"memberLoginHook": {
"id": "1bb4ca87-d9f6-4ccb-a2a4-0249b19699b3",
"occupation": "C3PO",
"positions": [
{
"id": "f4deaf82-ad87-472b-82ab-c78d08138526"
}
]
}
}
}
It is also worth noting I have found someone else who has the same issue:
https://forum.serverless.com/t/highly-confusing-express-router-issue/10987/8
i’m aware what trigger the issue, very strange bug has very strange solution.
Try lo disable Serverless Framework Enterprise (if it’s enabled), you can just comment the tenant and app rows into your serverless.yml file, and deploy the app again.
I think that there’s a bug in the last version of the serverless-sdk.

Gatsby build fails with "Cannot read property 'page_blocks' of null"

I have a Gatsby site that retrieves data from a Wordpress Rest endpoint.
I am able to run gatsby develop locally on my laptop, but when I run gatsby build on my server to deploy my site, the process crashes and I get the following output with an error at the end:
success open and validate gatsby-configs - 0.085s
success load plugins - 0.523s
success onPreInit - 0.005s
success delete html and css files from previous builds - 0.021s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.022s
success copy gatsby files - 0.040s
success onPreBootstrap - 0.014s
success createSchemaCustomization - 0.009s
-> wordpress__acf_options fetched : 1
-> wordpress__acf_v2 fetched : 1
-> wordpress__wp_api_menus_v2 fetched : 1
-> wordpress__wp_api_menus_menus_items fetched : 1
-> wordpress__wp_api_menus_menus fetched : 1
-> wordpress__wp_api_menus_menu_locations fetched : 1
-> wordpress__wp_v2 fetched : 1
-> wordpress__POST fetched : 1
-> wordpress__PAGE fetched : 7
-> wordpress__wp_media fetched : 0
-> wordpress__wp_blocks fetched : 0
-> wordpress__wp_types fetched : 1
-> wordpress__wp_statuses fetched : 1
-> wordpress__wp_taxonomies fetched : 1
-> wordpress__CATEGORY fetched : 1
-> wordpress__TAG fetched : 0
-> wordpress__wp_users fetched : 1
-> wordpress__wp_comments fetched : 1
-> wordpress__wp_search fetched : 8
Path: /wp-json/wp/v2/themes?per_page=100&page=1
The server response was "400 Bad Request"
Inner exception message: "Missing parameter(s): status"
success source and transform nodes - 3.437s
warn Plugin `gatsby-source-filesystem` tried to define the GraphQL type `File`, which has already been defined by the plugin `null`.
warn Plugin `gatsby-source-filesystem` tried to define the GraphQL type `File`, which has already been defined by the plugin `null`.
warn Plugin `gatsby-source-filesystem` tried to define the GraphQL type `File`, which has already been defined by the plugin `null`.
success building schema - 0.864s
success createPages - 0.060s
success createPagesStatefully - 0.080s
success onPreExtractQueries - 0.003s
success update schema - 0.048s
success extract queries from components - 0.384s
success write out requires - 0.006s
success write out redirect data - 0.005s
success onPostBootstrap - 0.004s
⠀
info bootstrap finished - 9.141 s
⠀
success Building production JavaScript and CSS bundles - 9.280s
success run queries - 9.547s - 10/10 1.05/s
failed Building static HTML for pages - 0.882s
ERROR #95313
Building static HTML failed for path "/join-us"
See our docs page for more info on this error: https://gatsby.dev/debug-html
10 | const PageTemplate = ({ data }) => (
11 | <Layout>
> 12 | { renderBlocks(data.currentPage.acf.page_blocks, data) }
| ^
13 | </Layout>
14 | );
15 |
WebpackError: TypeError: Cannot read property 'page_blocks' of null
- page.js:12 PageTemplate
src/templates/page.js:12:45
The issue seems to be occurring in the output of a GraphQL query that provides me with the data object. But this doesn't happen in my local setup, and it seems like the GraphQL connection is working and fetching data earlier in the error output. If there were issues with my query or something else then why would the local version be working?
This is the file where the issue is happening:
import React from 'react';
import { graphql } from 'gatsby';
import renderBlocks from '../js/pageBlockRender';
import Layout from '../components/global/Layout';
import '../components/sass/blocks.scss';
const PageTemplate = ({ data }) => (
<Layout>
{ renderBlocks(data.currentPage.acf.page_blocks, data) }
</Layout>
);
export default PageTemplate;
export const pageQuery = graphql`
query ($id: String!) {
currentPage: wordpressPage(id: {eq: $id}) {
title
id
parent {
id
}
template
acf {
page_blocks {
block_type {
acf_fc_layout
cs_title
cs_text
dl_style
hh_background_video
tpc_thought_piece {
post_title
post_excerpt
}
}
wordpress_id
}
}
}
}
`;
I'm using the latest versions of React and React-dom, and per this post I have also tried installing all peer dependencies in node. I've also tried deleting my .cache folder to no avail.
What could be different about gatsby develop and gatsby build that creates this issue?
Could it be the differences between the environment in which the dev and production environment are?
Dev Environment
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU # 2.70GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.10.0 - ~/.nvm/versions/node/v11.10.0/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v11.10.0/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 79.0.3945.130
Firefox: 58.0.1
Safari: 11.1.2
npmPackages:
gatsby: ^2.19.5 => 2.19.5
gatsby-image: ^2.2.38 => 2.2.38
gatsby-plugin-react-helmet: ^3.1.18 => 3.1.18
gatsby-plugin-sass: ^2.1.26 => 2.1.26
gatsby-plugin-sharp: ^2.3.13 => 2.3.13
gatsby-plugin-styled-components: ^3.1.14 => 3.1.14
gatsby-source-wordpress: ^3.1.51 => 3.1.51
gatsby-transformer-sharp: ^2.3.12 => 2.3.12
npmGlobalPackages:
gatsby-cli: 2.8.16
Prod Environment:
System:
OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
CPU: (4) x64 Intel Xeon Processor (Skylake, IBRS)
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 11.10.0 - ~/.nvm/versions/node/v11.10.0/bin/node
npm: 6.7.0 - ~/.nvm/versions/node/v11.10.0/bin/npm
Languages:
Python: 2.7.17 - /usr/bin/python
npmPackages:
gatsby: ^2.19.5 => 2.19.5
gatsby-image: ^2.2.38 => 2.2.38
gatsby-plugin-react-helmet: ^3.1.18 => 3.1.18
gatsby-plugin-sass: ^2.1.26 => 2.1.26
gatsby-plugin-sharp: ^2.3.13 => 2.3.13
gatsby-plugin-styled-components: ^3.1.14 => 3.1.14
gatsby-source-wordpress: ^3.1.51 => 3.1.51
gatsby-transformer-sharp: ^2.3.12 => 2.3.12
npmGlobalPackages:
gatsby-cli: 2.8.27
Here is my gatsby-config.js
/**
* Configure your Gatsby site with this file.
*
* See: https://www.gatsbyjs.org/docs/gatsby-config/
*/
module.exports = {
siteMetadata: {
title: "{PRIVATE INFO CAN'T MAKE PUBLIC}",
description: "{PRIVATE INFO CAN'T MAKE PUBLIC}",
author: `{PRIVATE INFO CAN'T MAKE PUBLIC}`
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages/`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `data`,
path: `${__dirname}/src/data/`,
ignore: [`**/\.*`], // ignore files starting with a dot
},
},
'gatsby-plugin-styled-components',
/** Comment this ↓ out to connect Gatsby to the staging site **/
{
resolve: 'gatsby-source-wordpress',
options: {
excludedRoutes: ['/wp/v2/users/**', '/wp/v2/settings*'],
baseUrl: '{PRIVATE INFO CAN'T MAKE PUBLIC}/',
auth: {
htaccess_user: "{PRIVATE INFO CAN'T MAKE PUBLIC}",
htaccess_pass: "{PRIVATE INFO CAN'T MAKE PUBLIC}",
},
protocol: 'https',
hostingWPCOM: false,
useACF: true,
searchAndReplaceContentUrls: {
sourceUrl: '{PRIVATE INFO CAN'T MAKE PUBLIC}/',
replacementUrl: '',
},
},
},
`gatsby-plugin-sass`,
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/data/`,
},
},
],
}
Here is package.json
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "A simplified bare-bones starter for Gatsby",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"babel-plugin-styled-components": "^1.10.6",
"bootstrap": "^4.4.1",
"gatsby": "^2.19.5",
"gatsby-image": "^2.2.38",
"gatsby-plugin-react-helmet": "^3.1.18",
"gatsby-plugin-sass": "^2.1.26",
"gatsby-plugin-sharp": "^2.3.13",
"gatsby-plugin-styled-components": "^3.1.14",
"gatsby-source-wordpress": "^3.1.51",
"gatsby-transformer-sharp": "^2.3.12",
"jquery": "^3.4.1",
"node-sass": "^4.13.1",
"popper.js": "^1.16.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^5.2.1",
"sharp": "^0.24.0",
"slash": "^3.0.0",
"styled-components": "^4.4.1",
"typescript": "^3.7.5",
"utf-8-validate": "^5.0.2"
},
"devDependencies": {
"popper": "^1.0.1",
"prettier": "^1.19.1"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"optionalDependencies": {
"bufferutil": "^4.0.1"
}
}
Any clues?

composer to disable https completely

my network does not work well with https, so doing
composer.phar install
throws
[Composer\Downloader\TransportException]
The "https://packagist.org/packages.json" file could not be downloaded: Failed to enable crypto
failed to open stream: operation failed
i used
{
"packagist": false
},
{
"type": "composer",
"url": "http://packagist.org",
"options": {
"ssl": {
"verify_peer": "false"
}
}
}
as a http falback, but again it crashes in some other point:
Installing dependencies
- Installing symfony/translation (v2.4.0)
Downloading: 100%
Downloading: 100%
Downloading: 100%
[Composer\Downloader\TransportException]
The "https://api.github.com/repos/symfony/Translation/zipball/0919e0fc709217f8c9e5049f2603419fdd4a34ff" file could not be downloaded: Failed to
enable crypto
failed to open stream: operation failed
my problem is just with TLSv1, previous SSL versions should work, as the browsers work correctly.
how should i do, the problem also exists in other cmd tools that depend on https like npm, bower, git, curl, ...
composer config --global disable-tls true
composer config --global secure-http false
You can turn off TLS (For your specific project) using your composer.json as such:
{
"require": {
"laravel/framework": "5.2.43"
},
"config": {
"preferred-install": "dist",
"disable-tls": true,
"secure-http": false
}
}
NB: Take not of the "disable-tls": true in the config section.
The problem is simply that you wrapped "false" in quotes, which is true when converted to bool.
Use "verify_peer": false instead of "verify_peer": "false":
{
"repositories": [
{
"type": "composer",
"url": "http://packagist.org",
"options": {
"ssl": {
"verify_peer": false
}
}
}
]
}
It's okey.
It will work. You just have a mismatch:
"options": {
"ssl": {
"verify_peer": false
}
}
in order to disable https totaly (not recommanded)
you need to add "secure-http": false in your composer.json file config key like this:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "5.3.*",
},
...
"config": {
"preferred-install": "dist",
"bin-dir": "vendor/bin/",
"secure-http": false
},
"minimum-stability": "dev"
}
You cannot disable SSL with Composer. Even if it works like in your setup, you cannot control the source URLs of any package you use. Some of them do not offer anything without SSL, so you MUST use SSL.
I think it's the best idea to make SSL work. Did you try composer diag and see where the problem is?