-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any reason not to include data fetching logic? #13
Comments
I had the same thought, but it turns out CORs will prevent one site from requesting the HTML from another. It's pretty easy to create an endpoint for this anyway. Here's my implementation with NestJS. link.controller.tsimport { Controller, Get, Query } from '@nestjs/common'
import { LinkService } from 'src/link/link.service'
@Controller('link')
export class LinkController {
constructor(private readonly linkService: LinkService) {}
@Get()
link(@Query('url') url: string) {
return this.linkService.getMetadata(url)
}
} link.service.tsimport { Injectable, HttpService } from '@nestjs/common'
import { getMetadata } from 'page-metadata-parser'
import domino from 'domino'
@Injectable()
export class LinkService {
constructor(private readonly httpService: HttpService) {}
async getMetadata(url: string) {
const res = await this.httpService.get(url).toPromise()
const doc = domino.createWindow(res.data).document
const meta = getMetadata(doc, url)
return {
success: 1,
meta: {
...meta,
image: {
url: meta.image ?? meta.icon ?? '',
},
},
}
}
} |
I am using editorjs with PHP and I have no idea of how I should do this at the moment. Having some examples would be of real help, indeed. |
|
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that extracting meta data from url could be implemented in this extension.
But according to the guide, users should implement that logic in their own server.
I am just curious that there is some reason like security or something.
The text was updated successfully, but these errors were encountered: