I have the following directory structure in my Nextjs app:
pages/post/[id]/index.js
I am trying to configure Amplify to correctly route this URL:
mydomain.com/post/123
I have the following rewrite configured:
{
"source": "/post/<*>",
"target": "/post/[id]/index.html",
"status": "200",
"condition": null
},
But it isn't working. What is the correct format for the Amplify rewrite when the directory is a dynamic route?
My routes do work when running locally. I can't get it configured in Amplify.
If you want to have mydomain.com/post/123 work, then your directory needs to match this route:
pages
|
+-- post
| |
| \-- [id].js
With your directory structure, the dynamic route doesn't know which file to load since index.js is resolved for a folder route such as /posts
Creating a file with the square braces will catch your /123 route as mentioned in the next.js docs: https://nextjs.org/docs/routing/dynamic-routes
The current rewrite rule you have should work for this structure where you do something like this as the rule:
{
"source": "/post/<*>",
"target": "/post/[id].html",
"status": "200",
"condition": null
}
This one worked for me:
{
"source": "/legal/<*>",
"target": "/legal/[pid]/index.html",
"status": "404-200",
"condition": null
}
Source address
Target address
Type
Country code
/legal/<*>
/legal/[pid]/index.html
404 (Rewrite)
-
Related
I'm trying to create firebase dynamic link for url like: example.com/<path>/<some_path>.
example.com will only be used for dynamic links and has already been hosted on firebase.
The firebase config that I'm using is:
{
"hosting": {
"appAssociation": "AUTO",
"rewrites": [
{
"source": "/**",
"dynamicLinks": true
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
I've created some dynamic links with the associated domain from dashboard with short url example.com/b. When I open this url, it shows message "Dynamic Link Not Found". And for example.com/b/some it shows Failed to resolve uri domain prefix: https://example.com/b.
So, my questions are:
Is the config correct?
Is creating dynamic links with url format example.com/<path>/<some_path> supported? How?
Are there any workarounds on how to implement this using dynamic links or am I missing the whole point of this?
I'm trying to get every url in a subdomain to be routed through a firebase function. This is my configuration:
The functions file:
const functions = require('firebase-functions');
exports.handleWebRequest = functions
.region('europe-west1')
.https
.onRequest((req, res) => {
res.send('Currently down.');
});
My firebase.json:
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "handleWebRequest"
}
]
},
"functions": {
"source": "firebase-functions",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
When I deploy the hosting and functions, and go to the URL in my browser, I expect to see "Currently down" for every route I open. However, every route except the root route shows the "Currently down" message, and the root route shows the index.html that I deployed.
So, in a nutshell:
/ shows my index.html (which I don't want)
/whatever shows "Currently down." (which is what I want)
The reason I'm trying to route everything through the function, is because I want to shield the website with HTTP Basic Auth, which is "not natively supported" by Firebase.
This is most probably because you still have the index.html file under the public folder.
As explained in the doc:
Note: The static files in the public directory take precedence over
the rewrites, so any static files will be served alongside the Cloud
Functions endpoints.
If you remove the index.html file it should work the way you expect.
Your function is deployed to the "europe-west1" region, but Firebase Hosting currently only supports the default "us-central1". This is stated in the documentation:
Important: Firebase Hosting supports Cloud Functions in us-central1 only.
I have the following structure (to handle different theming) using different websites on Firebase.
/src
/theme-1/index.html
/theme-2/index.html
All the "juice" is within src and the file index.html is the same for both theme-1 and theme-2 with exception of the line where I refer to the .css file, where I use actually a different on.
For the moment, I only configured one target but I will add more in my firebase.json:
{
"hosting": {
"target": "theme-1",
"public": "theme-1",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{"source": "**","destination": "/theme-1/index.html"}
],
"cleanUrls": true,
"headers": [ {
"source": "**",
"headers": [ {
"key": "Cache-Control",
"value": "max-age=60"
} ]
} ]
}
}
I then configure my target using the cmd commands to point to my firebase site:
firebase target:apply hosting theme-1 theme-1
and subsequently deploy the website:
firebase deploy
However, when I visit the page (despite it working locally), it seems not to be able to find the root folder /src (404 error).
How can I also include the folder /src in my deployment such that it works in the same way?
Only the directory specified by public is deployed to Firebase. The name is slightly misleading because there are no "private" files/directories.
So you have to do "public": "src" (or "public": "." if you want to deploy the theme directories as well), and adjust the other properties accordingly.
I'm developing web system using firebase hosting + functions.
Inspite of specifying rewrite rules on firebase.json,
a part of routing doesn't work.
root/
├ functions/
│ ├index.js
│ ├routes/
│ │ └ index.js
│ └views/
│ ├ index.jade
│ └ sub.jade
└ public/
└index.html // this is created by default. I don't want to use this.
This is my firebase.json
"rewrites": [{
"source": "**",
"function": "app"
}],
And this is node.js code.
router.get('/', function(req, res, next) {
res.render('index');
});
router.get('/subdir', function(req, res, next) {
res.render('sub');
});
result
https://myurl/ -> public/index.html is shown.(not handled on node.js)
https://myurl/ -> handled on node.js
Do you know how to handle root path request with node.js on firebase hosting.
See https://firebase.google.com/docs/hosting/full-config#hosting_priority_order .
Priority order of Hosting responses
The different Firebase Hosting configuration options described on this page can sometimes overlap. If there is a conflict, Hosting determines its response using the following priority order:
Reserved namespaces that begin with a /__/* path segment
Configured redirects
Exact-match static content
Configured rewrites
Custom 404 page
Default 404 page
Exact-match static content is high priority order than Configured rewrites.
So https://myurl/ get static content /index.html.
Can you try remove public/index.html?
I tried. I can rewrite.
See https://github.com/zkohi/firebase-hosting-using-functions-samples .
And you should check https://firebase.google.com/docs/hosting/functions .
Make a dummy folder that is empty. eg.: dummyApiFolder
Make a very simple cloud function. eg.
exports.bla = functions.https.onRequest(async (req, res) => {
res.send("server bla");
});
Use the following hosting rules
"hosting": {
"target": "api",
"public": "dummyApiFolder",
"rewrites": [
{
"source": "**",
"function": "bla"
}
]
}
3.1. target is only needed if you have set this up in your .firebaserc file
3.2. "public": "dummyApiFolder", is needed. Otherwise the CLI won't allow the deployment
Now all requests should get forwarded to bla.
The reason I'm advising to start with a simple cloud function is, express can be setup incorrectly. This can also give you an error, but you end up not knowing if it's a firebase issue or a code issue!
It's simple! Just rename the index.html file in the public directory into some other name. Also, just in case: In the firebase.json file, Change the public property's value
from public to .
i have created site ,name as testing under that created folder test.I am uploading images under test1 as sub folder under test by using rest API.i can get noderef of site by using url http://localhost:8081/alfresco/service/api/sites/testing
it give result like this
{
"url": "/alfresco/service/api/sites/testing",
"sitePreset": "site-dashboard",
"shortName": "testing",
"title": "Sample: Web Site Design Project",
"description": "This is a Sample Alfresco Team site.",
"node": "/alfresco/service/api/node/workspace/SpacesStore/b4cff62a-664d-4d45-9302-98723eac1319",
"tagScope": "/alfresco/service/api/tagscopes/workspace/SpacesStore/b4cff62a-664d-4d45-9302-98723eac1319",
"siteManagers":
[
"admin",
"mjackson"
],
"isPublic": true,
"visibility": "PUBLIC"
}
but i tried to get children of this by giving url
http://localhost:8081/alfresco/service/api/node/workspace/SpacesStore/b4cff62a-664d-4d45-9302-98723eac1319/children
it give 404 error please help this.I am using REST API