Skip to content

Commit

Permalink
feat: allow middlaware
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromtec committed Sep 24, 2024
1 parent c2922d7 commit c354522
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/cli/src/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,27 @@ function disableTsConfigStrictRules(basePath: string) {
})
}

function copyCoreFiles(basePath: string) {
const { coreDir, tmpDir } = withBasePath(basePath)
async function copyMiddlewareFile(basePath: string) {
const { tmpDir, userDir } = withBasePath(basePath)

const middlewarePath = path.join(userDir, 'middleware.ts')

if(!existsSync(middlewarePath)) {
console.log(`${chalk.yellow('warning')} - middleware.ts file not found`)
return
}

console.log(middlewarePath)
try {
copyFileSync(middlewarePath, path.join(tmpDir, 'src' , 'middleware.ts'))
console.log(`${chalk.green('success')} - Middleware file copied`)
}catch(error) {
console.error(error)
}
}

async function copyCoreFiles(basePath: string) {
const { coreDir, tmpDir, userStoreConfigFile } = withBasePath(basePath)

try {
copySync(coreDir, tmpDir, {
Expand All @@ -105,6 +124,12 @@ function copyCoreFiles(basePath: string) {
filterAndCopyPackageJson(basePath)
disableTsConfigStrictRules(basePath)

const userStoreConfig = await import(path.resolve(userStoreConfigFile))
console.log('enableMiddleware', userStoreConfig?.experimental?.enableMiddleware)
if(userStoreConfig?.experimental?.enableMiddleware) {
copyMiddlewareFile(basePath)
}

console.log(`${chalk.green('success')} - Core files copied`)
} catch (e) {
console.error(e)
Expand Down
1 change: 1 addition & 0 deletions packages/core/faststore.config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ module.exports = {
cypressVersion: 12,
enableCypressExtension: false,
noRobots: false,
enableMiddleware: false,
},
}

0 comments on commit c354522

Please sign in to comment.