Using Laravel-Websocket and Pusher Replacement.
I have no problem connecting to the same websocket server using http protocol.
But I could not connect using HTTPS. Can I just use HTTP and not setup SSL in the PHP side? What is the best solution for this? Thanks a lot!
NodeJS Code
const options = {
wsHost: "xxx",
wsPort: 6001,
wssPort: 6001,
key: "somekey",
broadcaster: "pusher",
forceTLS: false,
disableStats: true,
namespace: false,
enabledTransports: ['ws', 'wss'],
};
const client = new Pusher(options.key, options);
laravel config/broadcasting.php
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'host' => env('LARAVEL_WEBSOCKETS_HOST'),
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
'scheme' => 'http'
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
Related
Problem: I created an Elementor archive template to display the CPT posts on a category page. Yet, it shows no posts (CPT).
The CPT is called item. Here are the arguments:
$args = array(
'label' => __( 'Item', 'text_domain' ),
'description' => __( 'Add an Item', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'revisions', 'custom-fields', 'thumbnail', 'page-attributes'),
'taxonomies' => array('category', 'maker', 'material', 'condition'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-edit',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
Here are the template details and conditions:
When I test my template I get:
I was following this tutorial to create a web app that uses Cloudinary as a image host , I followed all the steps mentioned in it but when i try to add a image it gives me this error ErrorImage , idk what's causing this , is this some kind of connection error ?
here is my plugins.js
module.exports = ({ env }) => ({
upload: {
config:{
provider: 'cloudinary',
providerOptions: {
cloud_name: env('+++++++'),
api_key: env('8+++++++++++'),
api_secret: env('1T++++++++++++U'),
},
},
my .env file , this file also contains other stuff like jwt keys , host , port etc , here is what i added to it
--hosts ports etc--
CLOUDINARY_NAME = **********
CLOUDINARY_KEY = ***********
CLOUDINARY_SECRET = ***************
my middleware.js file
module.exports = [
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
'media-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];
I am working on a nestjs project using Kafka microservices (import from #nestjs/microservices).
for listening to a message, I am using the following code in main.ts:
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
transport: Transport.KAFKA,
options: {
client: {
brokers: configService.get('brokers'),
},
},
}),
inject: [ConfigService],
},
);
await app.listen();
I am trying to let the nestjs read brokers from .env.
It can not work.
and I got error :
Argument of type '{ imports: (typeof ConfigModule)[]; useFactory: (configService: ConfigService) => Promise<{ transport: Transport; options: { client: { brokers: any; }; }; }>; inject: (typeof ConfigService)[]; }' is not assignable to parameter of type 'NestApplicationContextOptions & MicroserviceOptions'.
Object literal may only specify known properties, and 'imports' does not exist in type 'NestApplicationContextOptions & MicroserviceOptions'.
if delete 'imports: [ConfigModule]', I have the following error:
Argument of type '{ useFactory: (configService: ConfigService) => Promise<{ transport: Transport; options: { client: { brokers: any; }; }; }>; inject: (typeof ConfigService)[]; }' is not assignable to parameter of type 'NestApplicationContextOptions & MicroserviceOptions'.
Object literal may only specify known properties, and 'useFactory' does not exist in type 'NestApplicationContextOptions & MicroserviceOptions'.
Please help :)
as I see that you included config module at root level, and you did not initialize it. I think you should add Config Module like below.
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
someModule,
fooModule,
],
useFactory: async (configService: ConfigService) => ({
transport: Transport.KAFKA,
options: {
client: {
brokers: configService.get('brokers'),
},
},
}),
inject: [ConfigService],
})
It's been seriously 10 days since i'm trying to deploy my web app online. i've gone back and forth between heroku and digital ocean. nothing solved. i've asked questions here all i get is a long post with technical terms i' not able to understand. Here's my problem :
i have a nuxt app with express.js in the backend and mongodb as the database. At first i had trouble with configuring host and port for my nuxt app. once i fixed it, anoither problem appeared : i'm not receiving data from the database. i don't if it's something related to database connection or with the express api configuration.
here's my nuxt config
export default {
ssr: false,
head: {
titleTemplate: 'Lokazz',
title: 'Lokazz',
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
},
{
hid: 'description',
name: 'description',
content:
'Lokazz'
}
],
link: [
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Work+Sans:300,400,500,600,700&subset=latin-ext'
}
]
},
css: [
'swiper/dist/css/swiper.css',
'~/static/fonts/Linearicons/Font/demo-files/demo.css',
'~/static/fonts/font-awesome/css/font-awesome.css',
'~/static/css/bootstrap.min.css',
'~/assets/scss/style.scss'
],
plugins: [
{ src: '~plugins/vueliate.js', ssr: false },
{ src: '~/plugins/swiper-plugin.js', ssr: false },
{ src: '~/plugins/vue-notification.js', ssr: false },
{ src: '~/plugins/axios.js'},
{ src: '~/plugins/lazyLoad.js', ssr: false },
{ src: '~/plugins/mask.js', ssr: false },
{ src: '~/plugins/toastr.js', ssr: false },
],
buildModules: [
'#nuxtjs/vuetify',
'#nuxtjs/style-resources',
'cookie-universal-nuxt'
],
styleResources: {
scss: './assets/scss/env.scss'
},
modules: ['#nuxtjs/axios', 'nuxt-i18n','vue-sweetalert2/nuxt', '#nuxtjs/auth-next', "bootstrap-vue/nuxt"],
bootstrapVue: {
bootstrapCSS: false, // here you can disable automatic bootstrapCSS in case you are loading it yourself using sass
bootstrapVueCSS: false, // CSS that is specific to bootstrapVue components can also be disabled. That way you won't load css for modules that you don't use
},
i18n: {
locales: [
{ code: 'en', file: 'en.json' },
],
strategy: 'no_prefix',
fallbackLocale: 'en',
lazy: true,
defaultLocale: 'en',
langDir: 'lang/locales/'
},
router: {
linkActiveClass: '',
linkExactActiveClass: 'active',
},
server: {
port: 8080, // default: 3000
host: '0.0.0.0' // default: localhost
},
auth: {
strategies: {
local: {
token: {
property: "token",
global: true,
},
redirect: {
"login": "/account/login",
"logout": "/",
"home": "/page/ajouter-produit",
"callback": false
},
endpoints: {
login: { url: "/login", method: "post" },
logout: false, // we don't have an endpoint for our logout in our API and we just remove the token from localstorage
user:false
}
}
}
},
};
here's my package.json
{
"name": "martfury_vue",
"version": "1.3.0",
"description": "Martfury - Multi-purpose Ecomerce template with vuejs",
"author": "nouthemes",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "8080"
}
},
}
here's my repository.js file
import Cookies from 'js-cookie';
import axios from 'axios';
const token = Cookies.get('id_token');
const baseDomain = 'https://lokazzfullapp-8t7ec.ondigitalocean.app';
export const customHeaders = {
'Content-Type': 'application/json',
Accept: 'application/json'
};
export const baseUrl = `${baseDomain}`;
export default axios.create({
baseUrl,
headers: customHeaders
});
export const serializeQuery = query => {
return Object.keys(query)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
.join('&');
};
an example of an api call i make locally that works without a problem :
import Repository, { serializeQuery } from '~/repositories/Repository.js';
import { baseUrl } from '~/repositories/Repository';
import axios from 'axios'
const url = baseUrl;
export const actions = {
async getProducts({ commit }, payload) {
const reponse = await axios.get(url)
.then(response => {
commit('setProducts', response.data);
return response.data;
})
.catch(error => ({ error: JSON.stringify(error) }));
return reponse;
},
}
here's my index.js (express file)
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose')
const cors = require('cors');
//const url = 'mongodb://localhost:27017/lokazz'
const url = 'mongodb+srv://lokazz:zaki123456#cluster0.hsd8d.mongodb.net/lokazz?retryWrites=true&w=majority'
const jwt = require('jsonwebtoken')
const con = mongoose.connection
mongoose.connect(url, {useNewUrlParser:true}).then(()=>{
const app = express();
// middlleware
app.use(express.json())
app.use(cors());
//products routes
const products = require('./product/product.router');
app.use('/', products)
//users routes
const users = require('./user/user.router');
app.use('/', users)
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server started on port ${port}`));
}).catch(error => console.log(error.reason));
con.on('open', () => {
console.log('connected...')
})
My directory structure
the error i get after the api request, meaning it's not receving any data.
ebd1ecd.js:2 TypeError: Cannot read properties of undefined (reading 'username')
at f.<anonymous> (c88240c.js:1)
at f.t._render (ebd1ecd.js:2)
at f.r (ebd1ecd.js:2)
at wn.get (ebd1ecd.js:2)
at new wn (ebd1ecd.js:2)
at t (ebd1ecd.js:2)
at f.In.$mount (ebd1ecd.js:2)
at init (ebd1ecd.js:2)
at ebd1ecd.js:2
at v (ebd1ecd.js:2)
idk if it's a problem with mongodb connection cluster or the api call.
global variable in JS is not able to access in jest test files, also not able to change the values which are already defined in global.
the work around I have did is as follow:
require('./../../../../bin/global');
describe('gloablAccessMethod', () => {
beforeEach(() => {
// jest.spyOn(regionConfig,'global.regionConfig').mockImplementation(() => ({
// 'ENABLE_CONFIG' : false
// }));
global.regionConfig.ENABLE_CONFIG = false;
});
const PHONE_PREFIX_SG = 65;
it('should access mock global variables', () =>{
//some sample tests
});
});
jest configuration
"jest": {
"timers": "fake",
"testEnvironment": "node",
"setupFiles": [
"./.jest/setEnv.js"
],
"setupFilesAfterEnv": [
"./.jest/setup.js"
],
"coverageReporters": [
"text",
"cobertura"
],
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
]
},```