Can't use EJS hook in Strapi showing error TypeError: ctx.render is not a function - ejs

What is the bug?
I am trying to render a page using strapi-hook-ejs but it is not working even I followed all official documentation.
It is giving following error
[2020-10-13T03:34:15.198Z] error TypeError: ctx.render is not a function
at Object.page (C:\Users\noman\Desktop\TestAPI\api\home\controllers\home.js:11:20)
at dispatch (C:\Users\noman\Desktop\TestAPI\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
at next (C:\Users\noman\Desktop\TestAPI\node_modules\koa-router\node_modules\koa-compose\index.js:45:18)
at dispatch (C:\Users\noman\Desktop\TestAPI\node_modules\koa-compose\index.js:42:32)
at C:\Users\noman\Desktop\TestAPI\node_modules\strapi\lib\middlewares\router\utils\routerChecker.js:79:28
at dispatch (C:\Users\noman\Desktop\TestAPI\node_modules\koa-compose\index.js:42:32)
at module.exports (C:\Users\noman\Desktop\TestAPI\node_modules\strapi-plugin-users-permissions\config\policies\permissions.js:86:9)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async C:\Users\noman\Desktop\TestAPI\node_modules\strapi-utils\lib\policy.js:68:5
at async serve (C:\Users\noman\Desktop\TestAPI\node_modules\koa-static\index.js:59:5)
at async C:\Users\noman\Desktop\TestAPI\node_modules\strapi\lib\middlewares\xss\index.js:26:9
[2020-10-13T03:34:15.212Z] debug GET /home/page (39 ms) 500
[2020-10-13T03:34:15.255Z] debug GET /favicon.ico (1 ms) 200
Steps to reproduce the behavior
I installed strapi-hook-ejs (npm i strapi-hook-ejs --save)
Create a new hook.json file in config folder. (./config/hook.json)
Added this code
{
"ejs": {
"enabled": true,
"layout": false,
"viewExt": "ejs",
"partial": true,
"cache": false,
"debug": true
}
}
Created views folder and a home.ejs file in it (./views/home.ejs) with this code <h1><%=title%></h1>
Then I created a new controller and point a route to it.
module.exports = {
page: async ctx => {
return ctx.render('home', {title: 'My app title'});
},
};
Now when I am going to this route I am getting the error.
Expected behavior
Should render home page
My Package.json
{
"name": "source-api",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"axios": "^0.20.0",
"strapi": "3.1.4",
"strapi-admin": "3.1.4",
"strapi-connector-mongoose": "3.1.4",
"strapi-hook-ejs": "^3.2.3",
"strapi-plugin-content-manager": "3.1.4",
"strapi-plugin-content-type-builder": "3.1.4",
"strapi-plugin-email": "3.1.4",
"strapi-plugin-upload": "3.1.4",
"strapi-plugin-users-permissions": "3.1.4",
"strapi-provider-upload-cloudinary": "^3.1.4",
"strapi-utils": "3.1.4"
},
"author": {
"name": "Nehal Ahmad"
},
"strapi": {
"uuid": "1034d7e9-73ba-49d4-8862-0d5d62ae7008"
},
"engines": {
"node": "12.x",
"npm": "6.x"
},
"license": "MIT"
}
System
Node.js version: v12.18.1
NPM version: 6.14.5
Strapi version: 3.1.4
Database: Mongo db
Operating system: Windows 10 pro
I have tried it on latest version of strapi.

I found answer on forum.strapi.io from user larsonnn
https://forum.strapi.io/t/cant-use-ejs-hook-showing-error-typeerror-ctx-render-is-not-a-function/416/9?u=nehal_ahmad

Related

Strapi 4.1.5 email plugin configuration

Unable to change email configuration. I specify the settings according to the instructions.
Restarted the server.
Removed cache and node_modules
In any case, the default plugin configuration is used.
node v14.18.2
strapi 4.1.5
{
"name": "strapi-test",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"#strapi/plugin-i18n": "4.1.5",
"#strapi/plugin-users-permissions": "4.1.5",
"#strapi/provider-email-nodemailer": "^4.1.5",
"#strapi/strapi": "4.1.5",
"sqlite3": "5.0.2"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "87e9d8e3-8c82-4c8e-8de4-990c2b729be4"
},
"engines": {
"node": ">=12.x.x <=16.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
SOLUTION https://github.com/strapi/strapi/issues/12919#issuecomment-1075954840
in case anyone looking for the answer for this.
like derick says, in strapi v4 the provider and providerOptions need to be wrapped inside config.
like this
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'nodemailer',
providerOptions: {
host: env('SMTP_HOST', 'smtp.gmail.com'),
port: env('SMTP_PORT', 465),
auth: {
user: env('SMTP_USERNAME', 'email#gmail.com'),
pass: env('SMTP_PASSWORD', 'password'),
},
},
settings: {
defaultFrom: 'email#gmail.com',
defaultReplyTo: 'email#gmail.com',
},
},
},
// ...
});

Parse error Unexpected token '�' at 1:1 ��{ on flutter app when running firebase deploy

encounter the below message when trying to firebase deploy from root project
Error: Parse Error in ...\firestore.indexes.json
Unexpected token '�' at 1:1
��{
I have a flutter app, upon which I also have a functions folder. Below is the file position:
AppFolder
functions
.eslintrc.js
index.js
package.json
etc
lib
files relative to flutter app
test
test files relative to flutter app
web firestore.indexes.json
firebase.json
etc
I am running on windows 11 in a newly built pc (so maybe sth is missing?), other devs are running on mac, I have changed the EOF sequence to LF on the 3 files of the functions folder, I have also run these two commands inside the functions folder
npm install firebase-functions#latest firebase-admin#latest --save
npm install -g firebase-tools
npm version is 8.1.2
node version is v16.13.1
firestore.indexes.json is:
{
"indexes": [
{
"collectionGroup": "something1",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "created",
"order": "DESCENDING"
},
{
"fieldPath": "something2",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "something3",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "something4",
"order": "ASCENDING"
},
{
"fieldPath": "something5",
"order": "DESCENDING"
}
]
}
],
"fieldOverrides": []
}
.elslint.js is
module.exports = {
"root": true,
"env": {
es6: true,
node: true,
},
"extends": [
"eslint:recommended",
"google",
],
"rules": {
quotes: ["error", "double"],
},
"parserOptions": {
"ecmaVersion": 2020,
},
};
and package.json is
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"axios": "^0.24.0",
"device-detector-js": "^3.0.0",
"firebase": "^9.2.0",
"firebase-admin": "^10.0.1",
"firebase-functions": "^3.16.0"
},
"devDependencies": {
"eslint": "^8.1.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.3.3"
},
"private": true
}
Please keep in mind that in an older pc running windows 10 and I can deploy by changing only to the LF and running the above commands.
Just try to make a new text file and copy the content of generated file inside the new one. Then override the new file with firestore.indexes.json
Its obvious that the generated json file has some formatting problem.
I recently had this problem and found that it was resolved by changes to the firebase.json file:
Seek "predeploy":
Delete the code so that the outcome is "predeploy": []
After this, run the firebase deploy function again, and everything should be fine.
Thank you to Max for sharing this solution with me : )

Heroku push rejected failed: npm ERR! 404 Not Found: event-stream#3.3.6. This causes a build fail

I am getting the error:
Heroku push rejected failed to define node.js node not defined in package.json
My app works locally, this is an Express MongoDB using handlebars. My gitignore has node_modules in it and the strange part is I am using nodemon and not node.
package.json:
{
"name": "Jukebox",
"version": "1.1.0",
"engines": {
"node": "11.3.0",
"npm": "6.4.1"
},
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^6.1.0",
"express": "~4.16.0",
"hbs": "~4.0.1",
"http-errors": "~1.6.2",
"method-override": "^3.0.0",
"mongoose": "^5.3.6",
"morgan": "~1.9.0",
"nodemon": "^1.18.4"
},
"description": "Jukebox is an app where users can add their favorite songs for others to discover. There will be a maximum number of 32 songs that can be added. When user selects genre the artists of that genre will populate the grid and a button will appear to add artist.",
"main": "app.js",
"repository": {
"type": "git",
"url": "git+https://github.com/chuckderosier/Jukebox.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/chuckderosier/Jukebox/issues"
},
"homepage": "https://github.com/chuckderosier/Jukebox#readme"
}
You need to specify a Node.js version within your package.json that matches
the runtime you’re developing and testing with.
Do the following:
Within your cmd line type: node --version and see what version of Node you're developing with.
Add an engines section within your package.json specifying your node version from step 1. For example something similar to this:
"engines": {
"node": "10.3.0"
}
For more information checkout the Heroku documentation for Nodejs buildpacks

How to interact with Windows Authentication and Users group using React.js .Net

I am curious how one would interact with Windows Authentication using React.js.
We have a little internal portal we are trying to set up, we already have predefined users groups and users that are in them. We are looking for a way to get those Authenticated credentials to the view using React.js. There are a couple of good links on how to get started with Reactjs.net but I don't see any tutorials on passing credentials to Reactjs.
Any suggested reading? Tutorials or maybe you know yourself and can provide direction?
enter link description here
I've found this really cool tutorial!
It says:
Here’s a minimal setup for React and Webpack based on what we did in this article. Now that you understand the steps, you can copy-paste this to your heart’s content.
package.json
Note: agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement.
{
"name": "ReactWebPackMVC5",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server –open –hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"agentkeepalive": "^3.5.1",
"babel-loader": "^8.0.2",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
}
}
webpack.config.js
Again, agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement. The same is true for the agent and onProxyRes properties.
const path = require("path"); const agent = require("agentkeepalive")
module.exports = { mode: "development", entry: "./Scripts/react/app.js", //or app.jsx output: { path: path.resolve(__dirname, "./Scripts/react/dist"), filename: "bundle.js", publicPath: "Scripts/react/dist" }, resolve: { extensions: ["*", ".js", ".jsx"] }, module: { rules: [ { test: /\.(js|jsx)/, exclude: /node_modules/, use: { loader: "babel-loader", options: { “presets”: [“#babel/preset-env”, “#babel/preset-react”] } } } ] }, devServer: { proxy: { "*": { target: "http://localhost:59829", changeOrigin: true, agent: new agent({ maxSockets: 100, keepAlive: true, maxFreeSockets: 10, keepAliveMsecs: 100000, timeout: 6000000, keepAliveTimeout: 90000 // free socket keepalive for 90 seconds }), onProxyRes: (proxyRes) => { var key = "www-authenticate"; proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(","); }, }, port: 8080, host: "0.0.0.0", hot: true, }, } };

Serentiy Report with protracor and cucumber

I have protractor cucumber example works fine, now I'm trying to create report by serenity.js
protractor.conf.js file
exports.config = {
getPageTimeout: 600000,
allScriptsTimeout: 700000,
framework: 'custom',
frameworkPath: require.resolve('serenity-js'),
capabilities: {
'browserName': 'chrome'
},
specs: [
'/home/git/adap_gateway/src/test/features/*.feature'
],
baseURL: 'http://localhost:8099/',
cucumberOpts: {
require: '/home/git/adap_gateway/src/test/javascript/stepDefinitions.js',
format: ['pretty'],
}
};
The feature file
Feature: Running Cucumber with Protractor
Scenario: Protractor and Cucumber Test
Given I go to "http://localhost:8099/#/"
When I add login credential
Then I go to scenario home page
Then I go to scenario details page
Then I go to edit attack tree page
Then build attack tree
ANd package.json file is
{
"name": "c",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"gulp": "^3.9.1",
"protractor-cucumber": "^0.1.8",
"protractor-cucumber-framework": "^3.1.0"
},
"devDependencies": {
"protractor-cucumber": "^0.1.8",
"serenity-cli": "^0.2.4",
"serenity-js": "^1.4.1",
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prereport": "serenity update",
"report": "serenity run"
},
"author": "",
"license": "ISC"
}
But I get
I get E/launcher - Error: Error: EACCES: permission denied, scandir '/etc/cups/ssl' at Error (native) at Object.fs.readdirSync (fs.js:952:18) at GlobSync._readdir (/home/ali/node_modules/cucumber/node_modules/glob/sync.js:2‌​88:41) [18:15:41] E/launcher - Process exited with error code 100,Do you have any instructions?
Can any one help me please to fix this problem?