Added directus api
This commit is contained in:
33
src/fetch-schema.js
Normal file
33
src/fetch-schema.js
Normal file
@ -0,0 +1,33 @@
|
||||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env.local') });
|
||||
|
||||
|
||||
async function fetchSchema() {
|
||||
// Define the Directus server URL and credentials
|
||||
const serverUrl = 'https://directus.andert.me';
|
||||
const credentials = {
|
||||
email: 'samuel@andert.me',
|
||||
password: process.env.DIRECTUS_PW
|
||||
};
|
||||
|
||||
// Login to the Directus server and get the access token
|
||||
const { data: { data: { token } } } = await axios.post(`${serverUrl}/auth/login`, credentials);
|
||||
|
||||
// Fetch the GraphQL SDL schema
|
||||
const { data: schema } = await axios.get(`${serverUrl}/server/specs/graphql`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${process.env.DIRECTUS_API}`
|
||||
}
|
||||
});
|
||||
|
||||
// Save the schema to a file
|
||||
fs.writeFileSync('./schema/directus.graphql', schema);
|
||||
}
|
||||
|
||||
fetchSchema().catch(console.error);
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
type Data = {
|
||||
|
Reference in New Issue
Block a user