I'm working in a project and I'm stuck in this thing. I don't know if I'm missing something or something is failing
I want to render a custom element using Express
framework in this way:
First I have the view file where I've declared the component in this way:
render.js from one component
<my-component><!-- # include virtual="/my-path" --></my-component>
Then, in another file (in another component) I'm receiving a request like this:
server.js from another component.
app.get('/my-path', (req, res) => {
res.send(render())
}
Where render()
method return an html, for example <div>hello</div>
.
And my-component
is not rended by default:
my-component.js
class WebComponent extends HTMLElement{
connectedCallback() {
console.log('connected component');
}
}
export default WebComponent;
Here, my expected workflow is:
- Load the view (render.js).
my-component
call /my-path
because the <!-- # include virtual="/my-path" -->
- The component is 'filled' with
/my-path
returned HTML.
- View the web component rendered by the server into client.
But it is not working, the component is not rendered and is empty.
I have tested accessing into http://localhost:XXXX/my-path
and the browser output the result correctly.
Also, the custom component display the message into console.log('connected component');
, so the component exists and starts.
But the path my-path
is not called... why? Have I missed something or am I mistaken?. Maybe I need render the web component, but then this is not SSI rendering from the server?
Also I've manually trigger my-path
route in the server to check if need to be called but it doesn't work either.
Edit:
I'm gonna edit to explain better:
I load web component in server side (or I think I do) in this way:
- Build and create a
page.js
file
- Into layout using
<script src="/my-path/page.js"></script>
- In
server.js
using: app.use('/my-path', express.static('./build'));
Thanks in advance.